使用RDLC报表(二)--使用自定义数据集
生活随笔
收集整理的這篇文章主要介紹了
使用RDLC报表(二)--使用自定义数据集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用RDLC報表(二)--使用自定義數據集
<!--[if !supportLists]-->1<!--[endif]-->新建窗體
?
<!--[if !supportLists]-->2<!--[endif]-->建立數據源
?
3<!--[endif]-->建立報表
?
新的數據報表已經生成,下面開始對數據源進行設置。
<!--[if !supportLists]-->4<!--[endif]-->對報表自動生成的數據源進行設置
選擇工具欄 à 報表 à 數據源,選中所要修改的數據源后,用“重命名”對其進行修改,如myds。
?
?
修改完成后,確定退出此窗口。
?
選中報表設計器內的表格,顯示屬性。將表格的數據集名稱更改為上面修改的名稱。
?
如果一個報表文件內只有一個數據源,則表格內的數據值可直接寫為“=Fields!字段.Value”的格式,如果包含多個數據源,則要對此字段的取值進行指定,如“=(Fields!字段.value,“數據集名稱””。
<!--[if !supportLists]-->5<!--[endif]-->手動生成數據源
手動生成的數據集內必須包含報表文件內設計的字段名稱,否則會運行出現錯誤。
生成數據集:
?
???????///?<summary>????????///?報表執行操作
????????///?</summary>
????????///?<param?name="sender"></param>
????????///?<param?name="e"></param>
????????private?void?button1_Click(object?sender,?EventArgs?e)
????????{
????????????//取得數據集
????????????string?connstring?=?"Data?Source=.;Initial?Catalog=Northwind;Integrated?Security=True";
????????????System.Data.SqlClient.SqlConnection?conn1?=?new?System.Data.SqlClient.SqlConnection(connstring);
????????????System.Data.SqlClient.SqlCommand?command1?=?new?System.Data.SqlClient.SqlCommand("select?*?from?customers",?conn1);
????????????System.Data.SqlClient.SqlDataAdapter?ada1?=?new?System.Data.SqlClient.SqlDataAdapter(command1);
????????????DataSet?c_ds?=?new?DataSet();
????????????try
????????????{
????????????????conn1.Open();
????????????????ada1.Fill(c_ds);
????????????}
????????????finally
????????????{
????????????????conn1.Close();
????????????????command1.Dispose();
????????????????conn1.Dispose();
????????????}
?
????????????//為報表瀏覽器指定報表文件
????????????this.reportViewer1.LocalReport.ReportEmbeddedResource?=?"report.Report1.rdlc";
????????????//指定數據集,數據集名稱后為表,不是DataSet類型的數據集
????????????this.reportViewer1.LocalReport.DataSources.Clear();
????????????this.reportViewer1.LocalReport.DataSources.Add(new?Microsoft.Reporting.WinForms.ReportDataSource("myds",?c_ds.Tables[0]));
????????????//顯示報表
????????????this.reportViewer1.RefreshReport();
????????}
?
運行后的數據顯示:
?
轉載于:https://www.cnblogs.com/chenbg2001/archive/2011/04/14/2016091.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的使用RDLC报表(二)--使用自定义数据集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (iPhone)怎样从photo alb
- 下一篇: Enterprise Library 企