Solved

visual basic 2010 ReportViewer question

Posted on 2011-09-16
17
524 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:Kevin Kilgore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
17 Comments
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 36549371
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:Kevin Kilgore
ID: 36549496
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
ID: 36549567
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:Kevin Kilgore
ID: 36549596
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
ID: 36550106
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:Kevin Kilgore
ID: 36550155
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:Kevin Kilgore
ID: 36550159
....meant to say the reportviewer came up with that error message ....
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 36550813
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
 

Author Comment

by:Kevin Kilgore
ID: 36551356
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
ID: 36551696
Add this to the top of your code page.

Imports Microsoft.Reporting.Winforms

OR

Add Microsoft.Reporting.Winforms. before Reportdatasource.
0
 

Author Comment

by:Kevin Kilgore
ID: 36551738
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:Kevin Kilgore
ID: 36551741
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
ID: 36564403
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:Kevin Kilgore
ID: 36564946
Is this the right screen you are referring to?
project.PNG
0
 
LVL 5

Accepted Solution

by:
puffdaddy411 earned 500 total points
ID: 36568835
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:Kevin Kilgore
ID: 36570633
Thanks for the info, I'll try this as soon as I get back to town today
0
 
LVL 5

Expert Comment

by:puffdaddy411
ID: 36571382
Great! What was your final code?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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