我有一个Windows窗体,我正在使用microsoftreportviewer,我可以使用一个数据集成功完成此操作。假设我有table table1,table2和table3,如何在ReportViewer_Load上以编程方式将所有这些添加到reportviewer?谢谢!
注意:所有这些表都有不同的列
答案 0 :(得分:0)
您是否希望一次按名称选择任何一个,然后将其绑定到报告?如果这是您正在寻找的,那么下面的代码可能会帮助您:
private DataTable GetData(string tableName)
{
DataSet ds = new DataSet();
string query = "Select * from something";
OdbcDataAdapter da = new OdbcDataAdapter(query, conn);
da.Fill(ds);
DataTable dt = ds.Tables[tableName];
return dt;
}
//You can fill the dataset once and then just get the table by table name. No necessary that you have to fill the dataset every time to get tables
private void RunReportViewer()
{
this.ReportViewer1.Reset();
this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
ReportDataSource rds = new ReportDataSource("#_your_table_Name", GetData());
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(rds);
this.ReportViewer1.DataBind();
this.ReportViewer1.LocalReport.Refresh();
}