码迷,mamicode.com
首页 > Windows程序 > 详细

关于FastReport在winform中的使用

时间:2018-04-23 18:49:11      阅读:971      评论:0      收藏:0      [点我收藏+]

标签:catch   fas   from   sel   ring   好的   中文   需要   send   

一、FastReport的简介

FastReport是功能齐全的报表控件,使开发者可以快速并高效地为·NET/VCL/COM/ActiveX应用程序添加报表支持。

二、FastReport的安装(推荐网址:https://www.cnblogs.com/yoyo-524/p/6116884.html

感觉写的安装步骤很详细了,在这就不赘述了。另外提一个小问题,就是按照步骤我们安装好的是英文,怎么转成中文呢?

大家不用再去网上找中文破解包之类的,直接在菜单里找到“File”——>“Select Language”,然后选择我们需要的中文简体就OK了。

三、在Winform中使用FastReport

先上代码,这里给报表附数据源,datatable和dataset都可以。

技术分享图片
 1 private void FormFR_Load(object sender, EventArgs e)
 2         {
 3             //DataSet data = null;
 4             DataTable dt = null;
 5             string conStr = "Server=‘127.0.0.1‘;database=demo;UID=‘sa‘;PWD=‘wsn931203‘;";
 6             try
 7             {
 8                 SqlConnection con = new SqlConnection(conStr);
 9                 con.Open();
10                 string sql = @"select Dept.DeptID,Dept.DeptName,UserInfo.UserName,UserInfo.Salary from dbo.Dept left join dbo.UserInfo 
11 on Dept.ID=UserInfo.DeptID";
12                 SqlCommand sqlcmd = new SqlCommand(sql, con);
13                 SqlDataAdapter sda = new SqlDataAdapter(sqlcmd);
14                 //data = new DataSet();
15                 dt = new DataTable();
16                 //sda.Fill(data);
17                 sda.Fill(dt);
18                 con.Close();
19                 sda.Dispose();
20             }
21             catch (Exception err)
22             {
23                 MessageBox.Show(err.StackTrace);
24             }
25 
26             try
27             {
28                 FastReport.Report report = new FastReport.Report();
29                 string filename = @"Reports\fr一览.frx";
30 
31                 report.Load(filename);
32                 report.Preview = this.previewControl1;
33                 //report.RegisterData(data);
34                 report.RegisterData(dt, "");
35                 report.SetParameterValue("time", DateTime.Now.Date.ToString("yyyy-MM-dd"));
36                 report.Show();
37             }
38             catch (Exception err)
39             {
40                 MessageBox.Show(err.Message);
41             }
42         }
View Code

后边的暂时先不写了,作者君有些小迷惑,等啥时候解决了再说吧。关于报表设计选择数据源和代码附数据源的问题。

关于FastReport在winform中的使用

标签:catch   fas   from   sel   ring   好的   中文   需要   send   

原文地址:https://www.cnblogs.com/wsn1203/p/8920507.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!