版主好,我要在Winform项目中给PageReport动态绑定数据源,我在博客中找到了ASP.net中动态绑定的案例,调试也成功了,参照着写了一个winform的,运行后报表显示错误。请帮我看一下是什么问题,代码和错误如附件,代码很简单:
private void Form3_Load(object sender, EventArgs e)
{
DisplayReportThread();
}
private void DisplayReportThread()
{
try
{
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
report.Load(new System.IO.FileInfo(@"..\..\PageReport1.rdlx"));
report.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
report.Run();
GrapeCity.ActiveReports.Document.PageDocument document1 = new GrapeCity.ActiveReports.Document.PageDocument(report);
viewer1.LoadDocument(document1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
void Document_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
{
if (args.DataSourceName == "DataSource1" && args.DataSetName == "DataSet1")
{
args.Data = GetData();
}
}
private DataTable GetData()
{
DataTable dt = new DataTable("");
dt.Columns.Add("Col1");
dt.Columns.Add("Col2");
dt.Columns.Add("Col3");
dt.Rows.Add(1, 1, 1);
dt.Rows.Add(2, 1, 1);
dt.Rows.Add(3, 1, 1);
dt.Rows.Add(4, 1, 1);
dt.Rows.Add(5, 1, 1);
dt.Rows.Add(6, 1, 1);
return dt;
}
|