views:

22

answers:

1

i am trying to do something like:

this.reportViewer.LocalReport.DataSources.Clear();
DataTable dt = new DataTable();
dt = this.inputValuesTableAdapter.GetData();    
Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource();

rprtDTSource = dt; // this line generates exception   

//this.reportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer.RefreshReport();

how can I load datatable as ReportDataSource?

the current code produces: "Cannot implicitly convert type 'System.Data.DataTable' to 'Microsoft.Reporting.WinForms.ReportDataSource' "

A: 

You are not initializing the ReportDataSouce correctly. Give this a try:

this.reportViewer.LocalReport.DataSources.Clear(); 
DataTable dt = new DataTable(); 
dt = this.inputValuesTableAdapter.GetData();     

Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt); 

this.reportViewer.LocalReport.DataSources.Add(rprtDTSource); 
this.reportViewer.RefreshReport(); 

Also, you might need to alter the first parameter to the ReportDataSource constructor to set the name of the datasource that your report is expecting.

madisonw
‘A data source instance has not been supplied for the data source’.. :(
ehmad11
As I mentioned at the end of my first post, you need to set the first parameter to the ReportDataSource constructor to the name of the data source your report is looking for. That name would have been at the error message your are getting now. So replace dt.TableName with a string containing that name.
madisonw