C#使用FastReport 报表初步体验(图文)

原来程序使用的Word和Excel来做一些导出数据和打印的操作,可是运行一段时间发现总有一些用户的电脑上安装的Office有些问题,还需要重新安装调整造成一些额外的维护工作。

这里通过简单尝试使用FastReport来代替Office,将一些需要导出的数据以报表的形式生成,需要的话可以另存成excel格式,这样就能减少一些不必要的麻烦。

程序里将连接信息从报表中提出来,避免报表文件的不安全,另外这个连接信息可以单独做到配置文件中即可。



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

namespace 测试FastReport
{
    public partial class Form1 : Form
    {
        private DataSet data; 

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string conStr = "Server='127.0.0.1';Initial catalog=WaiMaoJinKou;UID='sa';PWD='12345';Max Pool Size=512;";
            try
            {
                SqlConnection con = new SqlConnection(conStr);
                con.Open();
                SqlCommand sqlcmd = new SqlCommand();
                sqlcmd.Connection = con;
                sqlcmd.CommandText = @"SELECT * FROM [Event] ";
                SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
                data = new DataSet();
                sda.Fill(data);
                con.Close();
                sda.Dispose();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.StackTrace);
            }

            try
            {
                FastReport.Report report = new FastReport.Report();
                //string filename = Application.StartupPath + @"\FrxReport\qualityEvent.frx";
                string filename = @"D:\qualityEvent.frx";

                report.Load(filename);
                report.RegisterData(data);
                report.GetDataSource(data.Tables[0].TableName).Enabled = true;
                report.Show();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}
试了几次,只有使用.Net4.0的时候,FastReport才会被识别出来,所以开发的项目也需要重新设置一下,重新安装.Net4.0的框架包。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小飞鱼通达二开

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值