Assigning Reportviewer datasource at runtime?

B

Brett Romero

I have a winform with a reportviewer object on it. I'm trying to get
data from a datatable to display on the report. myDatatTable is
created and filled at runtime. I don't get any errors but only the
literal below displays in the report.

Microsoft.Reporting.WinForms.ReportDataSource rds = new
Microsoft.Reporting.WinForms.ReportDataSource();
rds.Name = myDataTable.TableName;
rds.Value = myDataTable;
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport();

In the report designer, I have a textbox with this in it

Fields!PersonCode.Value

I've also tried

=First(Fields!PersonCode.Value)

Any suggestions on what I'm doing wrong?

Thanks,
Brett
 
M

Miguel Martinez

first you should try changing the line:
reportViewer1.LocalReport.DataSources.Add(rds);

for something like this:
reportViewer1.LocalReport.DataSources.Add(new
ReportDataSource("dsDetallado_TBARCHIVO", dtTbl));

where "dsDetallado_TBARCHIVO" is the original name of the datasource you
use to design the report. The "dtTbl" is the new datatable that contains
the data.

I hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top