none
Manually create data source used to design report RRS feed

  • Question

  • I have an app that creates a datatable in memory and parses various pieces of information populating the datatable, all at runtime.  The fields are always constant so I would like to manually create a datasource that I can bind to a report so I can create the report at design time.  At runtime, when the user clicks the button to print the report, I would like to set the data source to my datatable and show the report.

    Are there any examples on the net that do this?  I've tried several different google searches without success.

    Any input appreciated.

    Saturday, September 6, 2008 9:05 PM

Answers

  • Hi Korazy,

    What you can do is add a DataSet to your project (Add New Item > DataSet). An xsd file will be added to your project and opened in the DataSet designer. In this designer, design what your data looks like, each field, name, datatype, etc.

    In the report RDLC file, add this DataSet as a data source. Then you can drag fields from it into the report and design your report with it.

    At runtime you need to provide your report with a ReportDataSource that has its name set to the same name as this DataSet in the RDLC file. Something like

    this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MyDataSetName", myObjectContainingTheData)); 

    Be careful using the smart tags that are part of the ReportViewer control, they will add plumbing code to try and do this for you, and conflict with what you are trying to do. Set the report for the ReportVIewer to use with the property grid instead, or programmatically.



    This is a common question, we are in the works of creating a blog entry and/or sample explaining it in nice detail. Stay tuned.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Matt E Greer Thursday, September 11, 2008 9:25 PM
    • Marked as answer by Korazy Friday, September 19, 2008 8:30 PM
    Thursday, September 11, 2008 9:25 PM