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/

相关文章:

WPF系统颜色: color of TextBox border

c# - 如何获取 ILNumerics 中 x 轴和 y 轴的当前最小值和最大值?

c# - NLog 类过滤器不起作用

c# - 如何在嵌入式浏览器中实现隔离 session 或多登录支持

c# - 保存到 Excel 文件会导致 C# Windows 中出现错误

c# - Windows 服务 : OnStart loop - do I need to delegate?

.NET 无法识别新安装的 GAC 程序集中的命名空间?

c# - 使用时区将字符串格式化为日期时间

c# - DataContext 在哪里?

wpf - 单击WPF组合框项或按Enter键选择时如何捕获事件?