Question

I need to add a second DataTable from our app's main DataSet into a report, but not having much luck.

We have several simple local reports in RDLC files, each with a single DataTable based on a view in our application DB. I need to improve one of the reports to add information from another table. This other table is defined in the same core DataSet which we use for reports in our .NET 2.0 WinForms application. Since the two tables are in the same DataSet, can I just make sure that both tables are loaded into the DataSet and then point the report at the DataSet instead of the DataTable? Something else?

Needless to say, I've been playing around with this for a while and not getting anywhere.

TIA, Matt

Was it helpful?

Solution

OK, I got this working and, in retrospect, it was pretty easy. I just didn't know which menus to use for getting VS to hook everything up, and which order to do them in.

Looking at the Designer.cs for my form was actually the most helpful thing I did. I noticed was that the ReportViewer has a default BindingSource pointed at the first table. Originally, I was hung up on trying to give the BindingSource a DataSet instead of a DataTable, but then I decided to try making a second BindingSource instead.

Maybe there's a better way, but here's basically what I ended up doing:

  1. With the RDLC in the designer, clicked the Report menu then Data Sources.

  2. On the Report Data Sources dialog, chose the additional DataTable from the drop-down and clicked Add to Report. (I also renamed the new data source to just be the name of the additional data table; VS had created some gigantic long name based on the full namesspace.) OK to close the dialog.

  3. On the designer for the form that contains my ReportViewer control, clicked the ReportViewer's smart tag (the little arrow in the top right corner of the control) and then selected Rebind Data Sources. This made a second BindingSource appear at the bottom of the Designer surface.

  4. Clicked the ReportViewer's smart tag again and this time chose "Choose Data Sources" to confirm that the ReportViewer now had two data sources, each bound to one of BindingSource instances now on the form.

  5. Revised the my form's OnLoad code to load rows into the second DataTable.

  6. Went back to the RDLC file, added a new table and set the detail cells to fields in the second DataTable -- and it worked!

Hopefully this will save someone else a couple hours someday.

OTHER TIPS

Figured out a way to use it in Visual Studio 2010. Click on View > ReportData and when the report data is seen , click on Datasources and then click on add. DO this as many times as the number of datasets needed.

Now in the smart tags of the reportviewer, click on choose datasources, this will show each of the datasets. To associate the datasets with a binding source, you will have to click on Project and then further click till you get the appropriate class, this will cause the binding sources to be created.

This work around is very useful if you have multiple tablixes and you have to associate a binding source to them within the same report when the report is displayed on the report viewer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top