信息发布→ 登录 注册 退出

C# 创建报表过程详解

发布时间:2026-01-11

点击量:

1、新建windows窗体,项目-->添加新项-->Visual C#项-->Windows Form-->windows窗体。

2、窗体中加入button按钮和报表控件。

3、新建报表,项目-->添加新项-->reporting-->报表,生成.rdlc文件。

4、在.rdlc上插入表格-->新建数据源-->数据库-->数据集-->新建连接,步骤如下:

5、这里输入数据库连接的服务器名,登录数据库的用户名和密码,选择数据库名称。

6、选择需要用的表。

7、名称可以自己写,本人没改,数据源为自己选择的数据库名称,可用数据集为表名。

8、.rdlc界面在表格的第一行输入字段名,第二行点击每列右上角的小图标选择该列要显示的字段名。

9、回到Form窗体点击报表右上角的小三角,选择刚刚创建的报表Report1.rdlc,数据源默认的就可以,本人在这里没有修改数据源名称还是DataSet1.

10、后台代码

  public Form1()
{
InitializeComponent();
this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load);
}

   private void button1_Click(object sender, EventArgs e)//button点击事件
{
reportViewer1_Load(sender, e);
}

   private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.Load -= new System.EventHandler(this.reportViewer1_Load);
}

private void reportViewer1_Load(object sender, EventArgs e)

{

DataTable table = helps.GetDataTable("select ID,UserID,OID from User_Org where 1=1");

this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", table));

this.reportViewer1.RefreshReport();

}

运行程序加载:

点击button

这里写的是点击button后才加载数据。

以上所述就是本文的全部内容了,希望大家能够喜欢。

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!