【发布时间】:2018-11-29 01:56:41
【问题描述】:
我正在报表查看器中构建报表。使用单个数据集,效果很好,但我需要在同一个报告中包含多个数据集。你能告诉我我做错了什么吗(如果可能的话,用一些代码)。我在这个问题上找到了一大堆信息,但一切都不是同一种编程语言。我正在使用 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 被正确填充。谢谢。
【问题讨论】:
标签: c# mysql rdlc reportviewer