c# - C# 中多个数据集 Winform 项目的 RDLC 问题

标签 c# mysql rdlc reportviewer

我正在报告查看器中构建报告。使用单个数据集,效果很好,但我需要在同一个报告中包含多个数据集。你能告诉我我做错了什么吗(如果可能的话,请提供一些代码)。我找到了关于这个问题的一大堆信息,但所有内容都不是使用相同的编程语言。我正在使用 C#。在 .RDLC 中,我创建了一个数据源和 2 个数据集(DataSet 和 DataSet1)。这是我当前的代码:

private void LoadReport()
    {
        try
        {
            MySqlConnection con = new MySqlConnection(conSettings.ToString());
            MySqlCommand cmd = new MySqlCommand("packing_slips", con);
            MySqlCommand cmd1 = new MySqlCommand("client_info", con);

            con.Open();
            cmd.Parameters.Add("@project", MySqlDbType.VarChar, 20).Value = project_id_box.Text;
            cmd.CommandType = CommandType.StoredProcedure;

            cmd1.Parameters.Add("@project", MySqlDbType.VarChar, 20).Value = project_id_box.Text;
            cmd1.CommandType = CommandType.StoredProcedure;

            MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
            MySqlDataAdapter adp1 = new MySqlDataAdapter(cmd1);

            DataSet ds = new DataSet();
            DataSet ds1 = new DataSet();
            adp.Fill(ds);
            adp1.Fill(ds1);

            reportViewer1.Reset();
            this.reportViewer1.LocalReport.DataSources.Clear();

            ReportDataSource reportDataSource = new ReportDataSource();
            reportDataSource.Value = ds.Tables[0];
            reportDataSource.Name = "DataSet";

            ReportDataSource reportDataSource1 = new ReportDataSource();
            reportDataSource1.Value = ds1.Tables[0];
            reportDataSource1.Name = "DataSet1";

            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
            this.reportViewer1.LocalReport.ReportPath = "project_report.rdlc";

            this.packing_slipsTableAdapter.Fill(this.shopmanagerDataSet.packing_slips);
            this.projectsTableAdapter.Fill(this.shopmanagerDataSet.projects);

            this.reportViewer1.RefreshReport();

            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

编译时我没有收到任何编译错误,但报告是空白的。我正在使用存储过程从 MySQL 数据库检索数据。调试时,我看到 ds 和 ds1 已正确填充。谢谢。

最佳答案

我找到了答案。将多个数据集添加到 RDLC 时,您需要在文本框属性中指定信息来自哪个数据集。例如:

=First(Fields!project_number.Value, "DataSet")

这为我解决了这个问题。上面的代码对于其他遇到此问题的人来说很有用。

关于c# - C# 中多个数据集 Winform 项目的 RDLC 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53524602/

相关文章:

c# - 如何在 C# 中不显示 PrintDialog() 直接打印 rdlc 报告?

.net - RDLC(VS 2010)如何访问DataObjects上的嵌套类或数组

c# - ServiceStack OrmLite - 处理默认列和计算列

c# - Entity Framework - 如何获取列?

c# - Azure 函数 TimerTrigger 仅运行一次

php - 将日期时间列作为表中的外键是否安全?

c# - 在 WPF 中共享应用程序资源

mysql - 我可以对未映射到表的实体使用 hibernate 查询语言吗?

mysql - 如何优化简单 Web 和数据库应用程序的响应时间

visual-studio-2008 - C#报表在PDF/打印模式下不会在新页面上重复字段