RDLC报表---自定义数据集
生活随笔
收集整理的這篇文章主要介紹了
RDLC报表---自定义数据集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//連接字符串
string connstr = "Data Source=.;Initial Catalog=WWALMDB;User ID=sa;Password=sqlsql";
//新建連接
SqlConnection connection = new SqlConnection(connstr);
//查詢命令
SqlCommand command = new SqlCommand(textBoxSQL.Text, connection);
//適配器
SqlDataAdapter adapter = new SqlDataAdapter(command);
//數據集
DataSet ds = new DataSet();
//查詢并填充
try
{
connection.Open();
adapter.Fill(ds);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
command.Dispose();
connection.Dispose();
}
//指定rdlc報表
this.reportViewer1.LocalReport.ReportEmbeddedResource = "FormReport.EventReport.rdlc";
//清空reportviewer先前的數據源
this.reportViewer1.LocalReport.DataSources.Clear();
//新建數據源
ReportDataSource rs = new ReportDataSource();
rs.Name = "EventHistory";//"EventHistory"是rdlc報表Tablib屬性下的數據集名稱
rs.Value = ds.Tables[0];
//添加數據源
this.reportViewer1.LocalReport.DataSources.Add(rs);
//顯示數據
this.reportViewer1.RefreshReport();
string connstr = "Data Source=.;Initial Catalog=WWALMDB;User ID=sa;Password=sqlsql";
//新建連接
SqlConnection connection = new SqlConnection(connstr);
//查詢命令
SqlCommand command = new SqlCommand(textBoxSQL.Text, connection);
//適配器
SqlDataAdapter adapter = new SqlDataAdapter(command);
//數據集
DataSet ds = new DataSet();
//查詢并填充
try
{
connection.Open();
adapter.Fill(ds);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
command.Dispose();
connection.Dispose();
}
//指定rdlc報表
this.reportViewer1.LocalReport.ReportEmbeddedResource = "FormReport.EventReport.rdlc";
//清空reportviewer先前的數據源
this.reportViewer1.LocalReport.DataSources.Clear();
//新建數據源
ReportDataSource rs = new ReportDataSource();
rs.Name = "EventHistory";//"EventHistory"是rdlc報表Tablib屬性下的數據集名稱
rs.Value = ds.Tables[0];
//添加數據源
this.reportViewer1.LocalReport.DataSources.Add(rs);
//顯示數據
this.reportViewer1.RefreshReport();
?
轉載于:https://www.cnblogs.com/jiewei915/archive/2010/11/24/1886536.html
總結
以上是生活随笔為你收集整理的RDLC报表---自定义数据集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 统计通话次数和时间的软件_通话时间统计器
- 下一篇: 吉林大学超星MOOC学习通高级语言程序设