2

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

Ryan Gates
  • 4,501
  • 6
  • 50
  • 90
Roshan
  • 287
  • 2
  • 4
  • 11
  • And does `dt.Tables[0]` really contain data? Also: is the data source in your report called `customer`? – marc_s Apr 09 '13 at 06:13
  • @ marc_s - yes,I tested it with forloop the data is in dataset in customer table, what should be the reportDataSource name should be ? Table name or dataset name? ` reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("customer", dt.Tables[0])) ;` – Roshan Apr 09 '13 at 06:22
  • The name of the data source **inside your report** needs to be the same as the one you're using when calling `new ReportDataSource(....)` - if you call it `customer` when creating the `ReportDataSource`, the data source name inside the `.RDLC` report must also be `Customer` – marc_s Apr 09 '13 at 06:31
  • @ marc_s - sorrry for the asking this , How to assign the `datasource` to `.RDLC` report ? – Roshan Apr 09 '13 at 06:41

3 Answers3

7

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?

Community
  • 1
  • 1
Ankush Madankar
  • 3,689
  • 4
  • 40
  • 74
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.

Damith
  • 62,401
  • 13
  • 102
  • 153
0

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.

Shruti Kapoor
  • 1,106
  • 2
  • 12
  • 32