Link to home
Start Free TrialLog in
Avatar of kdwood
kdwood

asked on

Visual Studio 2005 ReportViewer Control. URGENT HELP NEEDED!

Greetings experts,

I have a hot question for you that I would sure appreciate some quick help on.   I am trying to use the new ReportViewer control in VS 2005.  Unfortunately, I can't figure out an easy way to bind my existing dataset to the report.   Here is my flow:

1.  I DO NOT have pre-defined tables or datasets.  My application strictly uses run queries/stored procedures and builds datasets on the fly.
2.  I have a module function named GetOrderDetail(byVal myOrdNo) that retrieves data from our DB2 database.
3.  I created a from named rptActionReq.  On this form I have a ReportViewer control named ReportViewer1.

Now here is my questions in a nutshell:

A.  How can I bind the results of the GetOrderDetail() function to the ReportViewer control.
B.  Then, how do I bind the actual report fields to the data returned.


Thank you in advance for your help,

Keith
Avatar of kdwood
kdwood

ASKER


Well, I found a working solution by piecing together a couple of articles from another tech forum.  Here is a simplified version of how I handled this:

1.  Create a blank Data Source using the "Add New Datasource" option.  Choose the database type and do not select any database objects.
2.  Once the new Data Source is created, right click on it's name in the Data Sources Window and click "Edit with Data Designer."
3.  Now you will have a blank workspace open.  Right-click and chose "Add ---> Data Table."   This will insert a blank DataTable object on the workspace.
4.  Right-click on the newly created DataTable object and choose "Add ---> Column"   Type in your first column name, which MUST match the fields in your Dataset.
5.  Repeat step 4 for every column of data that you want to make available to your report from your DataSet.


On your Report:

1.  Open your report and choose the "Report ----> DataSources" option from the top menu bar"
2.  Select the DataSource that you just created using the steps above.
3.  You can now drag the fields onto your Report directly from the Data Sources window.

Now here is the code that binds your data to your report.  This must be on the Form that has the ReportViewer Control:

' my call to the Module function that retrieves the data

  Dim myTable As DataTable
  myTable = GetOrderDetail(myOrdNo)

' Now lets bind the returned data to the ReportViewer control

  Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "VOMTEST.ActReq.rdlc"
  Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("myDataSet_DataTable1", myTable))  
  Me.ReportViewer1.RefreshReport()

Notes:

"VOMTEST.ActReq.rdlc", is is the Actual RDLC file.  Make sure you include the project name which was VOMTEST in my case, or it will not work.

"myDataSet_DataTable1", is the DataSource that I selected on the Report Datasources menu option.

-----------------------

That's it!

 
I hope this will save somebody the headache that I went through trying to find out how to do this.

Best regards,

Keith

ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial