how to bind datasource to a .rdlc report in c#
Solution 1
When you add .rdlc report in your project by wizard then by default it take dataset name as 'DataSet1' . Now if you want to bind dynamically new dataset then name of that dataset must be 'DataSet1'. Try change it and also check that Table[0] contains some data(Rows) for which DataType get matched with original dataType of DataSet1
. If DataType doesn't matches then data wont come in your ReportViewer. Try this code:-
string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", yourDataSet.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();
For more detail about .rdlc report(Core logic) refer following link How to create report (RDLC) without database?
Solution 2
try below, may be the problem with data source name incorrect.
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(ds.DataSetName + "_" + ds.Tables[0].TableName, ds.Tables[0]));
you can check dataset name on the rdlc file content. check the name property of the dataset match with what you have given in the code.
Roshan
Updated on July 14, 2020Comments
-
Roshan almost 4 years
Friends , I have developed a simple application using c# , it has two rdlc reports
i used this below code to bind datasource to report viewer
this.reportViewer1.LocalReport.ReportPath = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\reports\reports\Report1.rdlc"; reportViewer1.LocalReport.DataSources.Clear(); reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("customer", dt.Tables[0])) ; this.reportViewer1.RefreshReport();
But when the report is generated ,it is empty report no data will displayed , any opinion???