c# - 如何在 rdlc c# 报告中使用多个数据集

标签 c# .net wpf winforms rdlc

首先,我需要通过 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/

相关文章:

c# - 如何重载泛型类的运算符?

c# - 下拉列表仅返回第一项的项目文本/值

c# - 现代化 'Hand Rolled' 数据访问库

c# - 使用正则表达式从字符串中提取子字符串

c# - 如何捕捉面板上的鼠标滚轮?

c# - 如何使用 WPF 将十进制值作为命令参数传递给命令?

c# - 保存WPF ViewModel当前状态

javascript - 确定 razor 生成 View 中 html 表的大小

c# - 我应该提交 visual studio 项目的哪一部分?

c# - 数据绑定(bind)到 EF 实体或 ViewModel