Roshan
Roshan

Reputation: 297

how to bind datasource to a .rdlc report in c#

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???

Upvotes: 2

Views: 21838

Answers (3)

Ankush Madankar
Ankush Madankar

Reputation: 3834

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?

Upvotes: 7

Shruti Kapoor
Shruti Kapoor

Reputation: 1136

This is how I update my data with object binding: In the Form1.cs file:

private myClass m_products = new Products();
public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           this.PaperBindingSource.DataSource = m_products.GetProducts();

The this.PaperBindingSource.DataSource is important.

Upvotes: 0

Damith
Damith

Reputation: 63105

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.

Upvotes: 2

Related Questions