Search code examples
c#asp.netrdlcstrongly-typed-dataset

How to Insert values to strongly typed DataSet from code and then show it from RDLC reporting page?


I have created an aspx page and added a Report viewer to it and script manager. I have also added a strongly typed DataSet file DataSet1.xsd in which there is a DataTable having 2 coloumns - Name and Designation. I have also used rdlc file which I have binded it with dataset1.

Now I want to put values to the data set from my code and then show it to report viewer.

aspx.cs code -

DataSet1 ds = new DataSet1();
DataRow dr = ds.DataTable1.NewRow();
ds.DataTable1.AddDataTable1Row("x","y");
this.ReportViewer1.LocalReport.Refresh();

I am not getting the values to the report.


Solution

  • You can add the DataSource to the Reportviewer from code behind. Try the following code.

    ReportDataSource datasource = new ReportDataSource("TableName", ds.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(datasource);