visual basic 2010 ReportViewer question

I've searched the web but can't find anything that works yet for this question:

I'm creating a report window in my vb 2010 program and give users options to select 2 different reports to run.  The ReportViewer Control only let's you run one report at a time.  How would i code this so that depending on which report the user selects, the single report viewer control will display the desired report based on user selection?

thanks!
Kevin KilgoreAsked:
Who is Participating?
 
puffdaddy411Connect With a Mentor Commented:
Try this below or change it based on the following topics.  The extra "_" is what is used to note the table within the dataset.  Is your Inventory table a strongly typed class or is it a datatable type?  If your data is in a strongly typed class named "Inventory", replace the "area51DataSet_r_SerialID" below with "Inventory" as the string.  If you have a datatable named "Inventory" inside the "area51DataSet" dataset, use "area51DataSet_Inventory" to pass the datatable string.


ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("area51DataSet_r_SerialID", InventoryBindingSource))
ReportViewer1.LocalReport.ReportEmbeddedResource = "Area_51.r_SerialID.rdlc"
ReportViewer1.RefreshReport()


You also may need to set your InventoryBindingSource.DataSource.  Use this prior to setting the reportdatasource.


'If it's a class
InventoryBindingSource.DataSource = Me.area51DataSet.Inventory
OR
'If it's a datatable
InventoryBindingSource.DataSource = Me.area51DataSet.Tables("Inventory")


Sorry, I just need more details about how your data is stored.
0
 
puffdaddy411Commented:
I use a combo box which displays the names of the available reports.  Depending upon the name selected, I load a different report.  You can use anything and simply add code to the changed event.

Something like this....

MainReportViewer.LocalReport.DataSources.Add(YourDataSourceInfo)
MainReportViewer.LocalReport.ReportPath = YourReportPath
'Add any parameters you have
MainReportViewer.RefreshReport
0
 
Kevin KilgoreAuthor Commented:
Gotcha...sorry, i'm new to this....on the part where you want me to put in "YourDataSourceInfo", what exactly needs to go there?  something like "me.MyDataSet" or "me.MyDataSet.MyBindingSource" ?  Also, should the "YourReportPath" be in quotations in the code?

thanks!
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
puffdaddy411Commented:
This all depends on how you set up your reportviewer object.  Are you dynamically loading your current report by setting the report path in code or did you select the report from the reportviewer control on your form?

Are your reports embedded in your project or are they stored in an external file location (C:|Reports or something)?

How is your current datasource set up?
0
 
Kevin KilgoreAuthor Commented:
At first i selected the report from the reportviewer control on my form but that did me no good since i need to display two reports at will instead of only one.  So i took that off...reports are embedded in the project.... on the report window form, i have 1 dataset, 1 table adapter, and 1 binding source....that's all so far....
0
 
puffdaddy411Commented:
Ok.  You may not need to do anything with the datasource in code since you have it set on the form.  Just use this to load different reports for embedded report.rdlc files.


MainReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectName.ReportName.rdlc"
MainReportViewer.RefreshReport


If your project is named "Project1" and your report is named "RPT1.rdlc" then it's as simple as that.  

MainReportViewer.LocalReport.ReportEmbeddedResource = "Project1.RPT1.rdlc"
0
 
Kevin KilgoreAuthor Commented:
Ok i think we are getting somewhere, i tried the suggestion above and it refreshed the report or at least it changed it to the one i wanted but it didn't generate the report because it had this error message:

"A Data Source Instance has not been supplied for the Data Source "MyReport.rdlc"
0
 
Kevin KilgoreAuthor Commented:
....meant to say the reportviewer came up with that error message ....
0
 
puffdaddy411Commented:
Ok.  You just need to set your datasource/bindingsource each time you refresh the control.  Whatever you are using that is on your form, we are going to set that in code.

MainReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSourceName", myBindingSource)
MainReportViewer.LocalReport.ReportEmbeddedResource = "YourProjectName.ReportName.rdlc"
MainReportViewer.RefreshReport

0
 
Kevin KilgoreAuthor Commented:
Ok, so I put the code in but it is underlining the "ReportDataSource" part and saying "Report Data Source is not definied"....Am I doing something wrong?  Here is my code:

 ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("area51DataSet", InventoryBindingSource)ReportViewer1.LocalReport.ReportEmbeddedResource = "Area_51.r_SerialID.rdlc"
 ReportViewer1.RefreshReport()

I have attached the actual code so you can see....
error-code.JPG
0
 
puffdaddy411Commented:
Add this to the top of your code page.

Imports Microsoft.Reporting.Winforms

OR

Add Microsoft.Reporting.Winforms. before Reportdatasource.
0
 
Kevin KilgoreAuthor Commented:
Tried both, still getting same error...i've attached what my form looks like and the code behind it...maybe that will help a little...thanks!
Public Class w_ReportCenter





    Private Sub w_ReportCenter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'area51DataSet.Inventory' table. You can move, or remove it, as needed.
        Me.InventoryTableAdapter.Fill(Me.area51DataSet.Inventory)
        Me.ReportViewer1.RefreshReport()

    End Sub

    
 

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click

        Me.Close()

    End Sub

    Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click

        If cboArea.Text = "Inventory" And cboReport.Text = "Master Report" Then




            ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("area51DataSet", InventoryBindingSource))
            ReportViewer1.LocalReport.ReportEmbeddedResource = "Area_51.r_SerialID.rdlc"
            ReportViewer1.RefreshReport()



        End If

    End Sub
End Class

Open in new window

form.JPG
0
 
Kevin KilgoreAuthor Commented:
I also left the coding out of the combo boxes so it wouldn't crowd the code i just gave you since it was a larger portion of code...just loading lists in the combo boxes...
0
 
puffdaddy411Commented:
Sorry for the delay.  Busy few days.

Can you take a screenshot of the data schema that is shown when you are viewing the rdlc designer?  We may have to recreate your reportviewer object.  We are trying to dynamically assign items but the way it is set up there on your form is a static method.  I would just like to see what is available to the report in the report designer.
0
 
Kevin KilgoreAuthor Commented:
Is this the right screen you are referring to?
project.PNG
0
 
Kevin KilgoreAuthor Commented:
Thanks for the info, I'll try this as soon as I get back to town today
0
 
puffdaddy411Commented:
Great! What was your final code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.