Hi,
I'm creating a small vb.net(VS2010) application and it has two datagridviews. I want to print the data on gridviews using reportviewer. So I'm trying to use two datasets. With one dataset I can print the gridview, but I don't understand how to use two datasets with the report. Can someone please help me. This is the code I used.
First I added a dataset and created a table on it. Then I used this code.
Dim dt As New DataTable
With dt
.Columns.Add("column1")
.Columns.Add("column2")
End With
For Each row As DataGridViewRow In datagridview.Rows
dt.Rows.Add(row.Cells(2).Value, row.Cells(3).Value)
Next
When you designed the RDLC, did you add 2 datasets to it?
Thank you for the reply. I can only add one data set. When I add two data sets to the report , the report doesn't show data. It shows me it cannot find data source for the second data set. I want to use two tablix on the report. A data set for each tablix. Thanks!
I created you a sample project that uses an RDLC file with 2 datasources defined. In the example the datasources are just pointing to simple objects I created (a customer and product class) instead of a database, but the concept is the same. Open it, and build it, and run it to see in action.
First, your not using any Datasets. You are using a DataTable. I haven't done any RDLC reports in years and you haven't explained what's in the two Datagridviews but it seems the answer is that you DON't need two Datsets, just two DataTables in one Dataset
Code:
Dim ds As New DataSet
Dim dt As New DataTable
With dt
.Columns.Add("column1")
.Columns.Add("column2")
End With
Dim dt2 As New DataTable
With dt2
.Columns.Add("column1")
.Columns.Add("column2")
End With
'LOAD the DataTables
'
'
ds.Tables.Add(dt)
ds.Tables.Add(dt2)
Report.ReportViewer1.LocalReport.DataSources.Add(ds)
Now a lot depends on how you created the report. Did you create it using a Type Dataset? You really need to provide more information.
I created you a sample project that uses an RDLC file with 2 datasources defined. In the example the datasources are just pointing to simple objects I created (a customer and product class) instead of a database, but the concept is the same. Open it, and build it, and run it to see in action.
kleinma Thank you very much for the example. I see you have added 2 data sets on your rdlc file.
Can you please tell me how did you add those two datasets. What I use to do is first goto the solution explorer , right click add new item add datasets then go to the rdlc file and add the dataset. I cannot see data sets in your projects solution explorer.
Thanks!
Last edited by dumiduw; Aug 14th, 2016 at 03:35 AM.
Here I have attached my project. It has a simple database file and two forms. One form is for datagridviews and other is for the report. It can print one dataset but I don't understand how to print another dataset using another tablix. Can you please check this. Thanks!
I took a quick look at your project and it seem your over complicating the problem. Why are you trying to use two datasets? Put all the reports tables in one dataset. Here's a walkthrough https://msdn.microsoft.com/en-us/lib...v=nav.90).aspx
Hi thank you very much for checking it. Actually I prefer to use two tables on one dataset on this, but when I tried, I got so many errors. I'll check your guide. Thanks!
Originally Posted by wes4dbt
I took a quick look at your project and it seem your over complicating the problem. Why are you trying to use two datasets? Put all the reports tables in one dataset. Here's a walkthrough https://msdn.microsoft.com/en-us/lib...v=nav.90).aspx
I tested @kleinma's way. Two classes as datasets, two binding sources on the reportviewer form and feeding the binding sources with gridview data in a loop . Its working fine thanks kleinma. Now I'm trying as @wes4dbt advised. two data tables in a dataset. Thank you all for the kind help.