views:

8

answers:

1

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

A: 

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.

Matt