vs2010自带的报表

本例用来显示Northwind中的order details表中的数据交分组

1.建立一WinForm程序,并建立一数据库连接,选择order details表,此时会自动建立一个xsd的数据集类,如下图

2.在项目中右键,新添加一个Report1.rdlc报表文件,并向此空白报表中添加一表格,如下图

数据集属性窗口中的“名称”是此报表的名称,在后面会用到,一定要记住。

以下为添加了表格的报表

3.从“报表数据”中把数据字段拖动到此表格中,行或列可以用右键“插入”功能即可。字段放好后,进行以orderid分组,

“行组”表示和字段显示在同一行中,“列组“是专门起了一列。

  

4.给组头及组尾中的相关属性框进行表达式设计(双击字段或函数就会自动写到表达式下)

  

给Quantity进行汇总,在其下面的对应的文本框中右键,设置其表达式

5.以下为设计好的报表

 

6.在Form1的窗体上放一reportViewer1,在Form1的load事件中写入如下代码:

复制代码
 private void Form1_Load(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myconstr"].ConnectionString))
            {
                SqlDataAdapter sda = new SqlDataAdapter("select * from [order details]", conn);
                conn.Open();
                DataSet ds = new DataSet();
                
                sda.Fill(ds, "Order Details");//表名为xsd中表的名称
                ReportDataSource RD = new ReportDataSource("DataSet1", ds.Tables[0]);//DataSet1为建立报表时用到的数据集名称

                this.reportViewer1.ProcessingMode=Microsoft.Reporting.WinForms.ProcessingMode.Local;
                this.reportViewer1.LocalReport.ReportPath=@"C:\Users\Administrator\Desktop\WindowsFormsApplication2\WindowsFormsApplication2\Report1.rdlc";
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(RD);
                this.reportViewer1.RefreshReport();
            }           
        
复制代码

  new ReportDataSource表示把现有的数据集和报表原来的数据集进行绑定

7.运行效果如下:

 

 

posted on   天上星  阅读(10491)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示