Thursday, March 8, 2012

assigning datasetname dynamically to a report ?

Hi friends
am new to reports in VS2005.
how can i assign a datasource dynamically to a report.
i know how to do add datasource in desgin mode to a report.(i.e i create a new datasource and drag and drop it on to report).

but in my case i need to take some parameters from users and create a dataset with relavant data and show it in a report.
i cant find any documentation or samples for it.
Thanks for your help.
BTW its winform application and i want to show that report in report viwer control.
Thanks for your helpFinally i found a way to do this.
first i created typed dataset and bound it to my report. and in my screen i populate this typed dataset with data and load the report in report viewer control.
my sample code

reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
reportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.samplereport.rdlc";
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource("MyTable", GetData()));
this.reportViewer1.RefreshReport();

in getdate() method i loop thru my data reader and populated the typed dataset .

is this right approach i.e. using typed dataset and is there any better approach of doing it.
Thanks for your ideas.

No comments:

Post a Comment