首先,我需要通过 TextBox
输入创建使用从数据库中选择的报告。如何获取文本框值并生成基于此 TextBox
的报告?如果我需要使用多个 DataSets
来用我的报告中的信息填充一些表格,该怎么做?注意:我使用 WPF 获取 TextBoxes
值并使用 Winforms 创建 reportViewer
。
private void Report_Load(object sender, EventArgs e)
{
DataSet dsr = new DataSet();
_con = new SqlConnection(_strCon);
_adp = new SqlDataAdapter("Select * from tbl_cad",_con);
_adp.Fill(dsr,dsr.Tables[0].TableName);
ReportDataSource rds = new ReportDataSource("tbl_cad",dsr.Tables[0]);
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.LocalReport.DataSources.Add(rds);
this.reportViewer.LocalReport.Refresh();
this.reportViewer.RefreshReport();
}
最佳答案
您可能需要澄清多个数据集???或单个数据集中的多个表。
使用 SQL 数据适配器,您可以在单个 DataTable 而不是 DataSet 上运行填充,然后将表添加到主数据集,最后将该数据集提供给报表。
举个例子...
DataSet dsr = new DataSet();
_con = new SqlConnection(_strCon);
_adp = new SqlDataAdapter("Select * from tbl_cad",_con);
DataTable tbl1 = new DataTable();
tbl1.TableName = "TableNameForReport";
_adp.Fill( tbl1 );
_adp = new SqlDataAdapter("Select * from OtherTable",_con);
DataTable tbl2 = new DataTable();
tbl2.TableName = "AnotherTableNameForReport";
_adp.Fill( tbl2 );
dsr.Tables.Add( tbl1 );
dsr.Tables.Add( tbl2 );
现在,您显然可以更改从源数据库获取数据所需的任何查询,然后将它们全部放入一个数据集中,它们应该可供您的报告运行。
关于c# - 如何在 rdlc c# 报告中使用多个数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32262272/