我尝试了很多解决方案,但我总是得到一个空的reportviewer
,我确信我的数据表不是空的。
这是我的代码:
private void Alarm_Filter_Submit_Button_Click(object sender, EventArgs e)
{
Report_Title_Label.Text = "Event Logs Report";
int siteId = FormAdminDAO.GetSiteId(customerId, siteName);
DataTable alarmDetailsTable =
FormAdminDAO.GetEventLogsReport(siteId, batteryIdString, batteryTypeString, startDate, endDate);
CurrentReportResultsTable = alarmDetailsTable;
alarmDetailsTable.TableName = "Table1";
reportViewer1.ProcessingMode = ProcessingMode.Local;
ReportDataSource source = new ReportDataSource("Table1", alarmDetailsTable);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(source);
reportViewer1.LocalReport.Refresh();
//Report_Table_Grid.DataSource = alarmDetailsTable;
Report_Table_Panel.Visible = true;
Alarm_Report_Filter_Panel.Visible = false;
}
我知道在DataGridView工作时正在正确检索DataTable但是当我尝试使用DataTable填充reportviewer时,我在reportviewer上显示了此消息:“尚未指定报告定义的来源。”
我尝试了多种解决方案,例如Using datatable as datasource in micrsosoft report viewer,Datatable as datasource in ReportViewer,How to bind datatable to reportviewer runtime,How can I load datatable as ReportDataSource?,但遗憾的是它们似乎不适用于我的项目。
请告诉我如何正确使用我的DataTable
来填充reportviewer
并且无法获得空ReportViewer
。