rdlc问题#

ax6ht2ek  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(325)

我正在报表查看器中生成报表。对于单个数据集,它工作得很好,但我需要在同一个报告中包括多个数据集。你能告诉我我做错了什么吗。我找到了一大堆关于这个问题的信息,但是所有的东西都不是用同一种编程语言。我用的是c。在.rdlc中,我创建了一个数据源和两个数据集(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被正确填充。谢谢。

siotufzp

siotufzp1#

我找到了答案。向rdlc添加多个数据集时,需要在textbox属性中指定信息来自哪个数据集。如:
=第一个(字段!项目编号.value,“数据集”)
帮我修好了。上面的代码对任何有此问题的人都是好的。

相关问题