• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

c#FastReport开发报表-实例1

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文介绍c#应用FastReport开发报表,因此首先附该工具下载地址:http://download.csdn.net/detail/hws1058648831a/6378499

下载解压后可以直接使用,里面还有相关实例供参考。

下面看看一个简单的例子:

1 打开visual studio 2010创建一个工程名称为WfmFastReport,编辑界面,然后添加FastReport.dll ,FastReport.Bars.dll,FastReport.Editor.dll的引用。

FastReport.dll ,FastReport.Bars.dll,FastReport.Editor.dll在下载包里有的。

代码非常简单,如下:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using FastReport;
using FastReport.Editor;

namespace WfmFastReport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private DataSet data;
        private void button1_Click(object sender, EventArgs e)
        {  

            string conStr = @"server=***;user id=**;password=***;initial catalog=****";
            try
            {
                SqlConnection con = new SqlConnection(conStr);
                con.Open();
                SqlCommand sqlcmd = new SqlCommand();
                sqlcmd.Connection = con;
                sqlcmd.CommandText = "select top 100 * from item";
                SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
                data = new DataSet();
                sda.Fill(data);
                con.Close();
                sda.Dispose();
                MessageBox.Show("加载数据成功!");
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
    
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                FastReport.Report report = new FastReport.Report();
                string filename = @"C:\Documents and Settings\Administrator\桌面\检查项目.frx";
                report.Load(filename);
                report.RegisterData(data);
                report.GetDataSource(data.Tables[0].TableName).Enabled = true;
                report.Show();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}

 

检查项目.frx文件就是FastReport设计出的报表模板,非常简单,有兴趣的朋友可以试一试。

下面看看效果:

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
第十九节:语法总结(4)之C# 7.x、8.0、9.0新语法发布时间:2022-07-13
下一篇:
谈谈c#对象初始化问题C#对象初始化 发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap