Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to make a MS Report using several datatables

0.00/5 (No votes)
8 Aug 2012 1  
How to make a MS Report using several datatables.

Introduction

The reason I’m making this how-to is, that I had a project which involved making a report (for the first time), and it had to be made using several tables from a database. I searched the web for answers but I didn’t find any useful or easy solution. I found answers where it was almost impossible to use more than one table in making reports. I’m sure that there are some solutions out there, but I didn’t find them. I was almost ready to give up after all these “good solutions” I found on the internet.

It took me some time to figure out how to make a report using several tables.

For this little project, you’ll need:

  • A database with several tables
  • Visual Studio 2010 (or 2008)

Let’s start the project:

  1. Open VS and choose New Project…:
  2. Choose Windows Forms Application and give it a name, in my case, it is “Tables2Report”…
  3. When Form1 appears, we will choose Add New Data Source:
  4. Choose “Database”, ”Next” -> “Dataset”, “Next” -> “New Connection…” and here choose your data source, server name, database name, and choose “Test Connection” to make sure that your choice is the right one. Click on OK. Now you have the connection to the database. Click on Next and give a name to the Connection String and click Next.
  5. Now choose your “Tables” and write a name for your DataSet and click Finish:
  6. Now you should have the Dataset with the tables in the Data Sources tab:
  7. Right click on the empty place in the Data Sources tab and choose Edit DataSet with Designer:
  8. Now you have the tables you chose.
  9. Right click on the empty place in the window and choose Add -> Table Adapter…:
  10. Choose your data connection (it will be the connection you saved earlier, and it has to be with the (Settings) at the end of the name. Click on Next two times and click on Query Builder…
  11. Choose your tables. Ctrl + Mouse left click on tables. Click on Add and Close.
  12. Now choose the columns you want to be on the report and press OK:
  13. Now show a window with the SQL statement. Press Finish to close the window and a new table is shown with the name Data Table1 with the columns you chose earlier.
  14. Click on Form1.cs [Design] tab to show the Form.
  15. From Toolbox, drag the ReportViewer icon to Form1.
  16. Arrange the size of the form and Report Viewer as you wish.
  17. On the upper right corner of Report Viewer, you will find a little white button with a triangle on it. Click on it with the mouse and you will get a little menu, there you will find Design a new report, choose it:
  18. Now you have the report wizard in front of you. Choose the Data Source you saved earlier, and from the Available datasets choose Data Table1 and press Next.
  19. Now you can arrange rows and values. It is easier to move everything to the Values window and press Next twice and Finish at last.
  20. You have your report with the new table.
  21. There is one thing to make sure before you’re ready to run your report software. Go back to Form1 [Design] and on the upper right corner of Report Viewer, push the little mark and press Choose Report’s triangle and choose the ……..rdlc.
  22. You’re ready to run the program.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here