Solved

visual basic 2010 ReportViewer question

Posted on 2011-09-16
17
517 Views
Last Modified: 2013-11-27
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!
0
Comment
Question by:rauschcoleman
  • 9
  • 8
17 Comments
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
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
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
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
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
....meant to say the reportviewer came up with that error message ....
0
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:rauschcoleman
Comment Utility
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
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
Add this to the top of your code page.

Imports Microsoft.Reporting.Winforms

OR

Add Microsoft.Reporting.Winforms. before Reportdatasource.
0
 

Author Comment

by:rauschcoleman
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
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
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
Is this the right screen you are referring to?
project.PNG
0
 
LVL 5

Accepted Solution

by:
puffdaddy411 earned 500 total points
Comment Utility
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
 

Author Comment

by:rauschcoleman
Comment Utility
Thanks for the info, I'll try this as soon as I get back to town today
0
 
LVL 5

Expert Comment

by:puffdaddy411
Comment Utility
Great! What was your final code?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now