user1868541
user1868541

Reputation:

C# - binding datatable to reportviewer

I'm trying to bind a DataTable to a reportviewer in winforms at runtime but I get this message in the reportviewer (not an exception)"

The source of the report definition has not been specified"

Here's my code:

this.rptViewer.LocalReport.DataSources.Clear(); 

ReportDataSource rprtDTSource = new ReportDataSource(dt.TableName, dt); 

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

any Ideas?

Upvotes: 2

Views: 2230

Answers (1)

Fabian Bigler
Fabian Bigler

Reputation: 10915

Try this instead:

var reportDataSource1 = new ReportDataSource { Name = "WpfApplication17_User", Value = _users };
string exeFolder = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
_reportViewer.LocalReport.ReportPath =exeFolder + @"\Reports\Report1.rdlc";
_reportViewer.LocalReport.DataSources.Add(reportDataSource1);
_reportViewer.RefreshReport();

Got the answer from here (Codeproject).

Upvotes: 2

Related Questions