RDLC Report With Two DataSets. How To ?
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
Report.ReportViewer1.LocalReport.DataSources.Item(0).Value = dt
Report.ShowDialog()
Report.Dispose()
How do I use two datasets to print the other gridview on the same report ?
Thanks!
Re: RDLC Report With Two DataSets. How To ?
When you designed the RDLC, did you add 2 datasets to it?
Re: RDLC Report With Two DataSets. How To ?
Quote:
Originally Posted by
kleinma
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!
Re: RDLC Report With Two DataSets. How To ?
If you set 2 data sources when designing the RDLC file, then when you set your datasource with valid data in this line of code
Report.ReportViewer1.LocalReport.DataSources.Item(0).Value = dt
you should also be setting the value of datasources.item(1).value, which would be the second datasource you had added.
Re: RDLC Report With Two DataSets. How To ?
Dim dt As New DataTable
With dt
.Columns.Add("Column1")
.Columns.Add("Column2")
End With
For Each row As DataGridViewRow In GV2.Rows
dt.Rows.Add(row.Cells(2).Value, row.Cells(3).Value)
Next
Dim dt2 As New DataTable
With dt2
.Columns.Add("Column1")
.Columns.Add("Column2")
End With
For Each row As DataGridViewRow In GV4.Rows
dt2.Rows.Add(row.Cells(2).Value, row.Cells(3).Value)
Next
Report.ReportViewer1.LocalReport.DataSources.Item(0).Value = dt
Report.ReportViewer1.LocalReport.DataSources.Item(1).Value = dt2
But When I run the project it highlights me the last line and shows me this error
"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Quote:
Originally Posted by
kleinma
If you set 2 data sources when designing the RDLC file, then when you set your datasource with valid data in this line of code
Report.ReportViewer1.LocalReport.DataSources.Item(0).Value = dt
you should also be setting the value of datasources.item(1).value, which would be the second datasource you had added.
1 Attachment(s)
Re: RDLC Report With Two DataSets. How To ?
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.
Re: RDLC Report With Two DataSets. How To ?
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.
1 Attachment(s)
Re: RDLC Report With Two DataSets. How To ?
Quote:
Originally Posted by
kleinma
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.
Attachment 140167
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!
Re: RDLC Report With Two DataSets. How To ?
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!
WindowsApplication1.zip
Re: RDLC Report With Two DataSets. How To ?
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
Re: RDLC Report With Two DataSets. How To ?
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!
Quote:
Originally Posted by
wes4dbt
Re: RDLC Report With Two DataSets. How To ?
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.
Re: RDLC Report With Two DataSets. How To ?
Sounds good. I am glad you are making progress.