?
Solved

Having trouble binding a ReportViewer to a DataSet

Posted on 2007-07-31
9
Medium Priority
?
1,706 Views
Last Modified: 2013-11-26
I am having trouble binding a ReportViewer to a previously defined Dataset.  Per solutions I have read on EE I have done the following:

1) The user selects various criteria from combo boxes & DateTimePickers and I create a dynamic SQL statement and fill a DataAdapter with a Dataset & Table as shown:
da.Fill(DS, "MyTable")

2) I have bound a Dataset to a DataGridView with the code:
dgvCoa.DataSource = DS.Tables("MyTable")

3) Stealing shamelessly from EE I created a "blank" dataset using the Add Datasource wizard, then I created a blank table and added columns to exactly match the schema of DS.Tables("MyTable")

4) I created a Report by dragging fields from the dataset in step 3

5) I created a "Print" button and added the following lines of code:
Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("dsCOA", Me.DS.Tables("MyTable")))
 Me.ReportViewer1.RefreshReport()

Where "dsCOA" is the blank dataset I created with the add datasource wizard

My report loads, but no data is present (only headers from the blank dataset).

I am going to need to create many reports with this method (or something similar) and I would be grateful for any assistance.

Thanks !!
0
Comment
Question by:SteveB2175
  • 6
  • 3
9 Comments
 

Author Comment

by:SteveB2175
ID: 19600151
As an update, I added the following lines:

 Me.ReportViewer1.Reset()
 Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.rptCoa.rdlc"

Ahead of

Me.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("dsCOA", Me.DS.Tables("MyTable")))
Me.ReportViewer1.RefreshReport()

Now I get the following message when I run the report:

A datasource instance has not been supplied for data source 'dsCOA_MyTable'
0
 
LVL 27

Accepted Solution

by:
VBRocks earned 2000 total points
ID: 19600673
Not sure about the Report Viewer...

But why don't you try out a Crystal Report?  

First, add a Strongly-Typed DataSet to your project:
    Project Menu | Add new Item...
    Select DataSet, and name it "MyDataSet"
    Once it opens, right-click on the designer, and select Add | DataTable
    Click on the table name and rename it "MyTable"
    Right-click on the table and select Add | Column to add as many columns as you need.
    Save your dataset

Once you have added a DataSet to your
project, then all you have to do is the following:

1.  Add a CrystalReport to your project:  
        Project menu | Add New Item...
        Select CrystalReport, name it "rptCoa"
        Use the Report Wizard to create a Standard report.
        Expand the Project Data tree node, then ADO.NET DataSets, then the DataSet you added to your
            project.  Select it by moving it to the right.
        Select the entire table, or desired fields to display.
        Click finish.
        Save and Build your project.

2.  Add a form to your project, and name it "frmViewer".
         Add a CrystalReportViewer to the form.

3.  On the frmViewer_Load event, add the following code to view your report:
        Dim ds As New MyDataSet()
        'Load your dataset (ds)

        'Create a new instance of the report
        Dim rpt As New rptCoa()

        'Set the report datasource to your loaded dataset
        rpt.SetDataSource(ds)

        'Set the report for the Viewer
        Me.CrystalReportViewer1.ReportSource = rpt
       

That's it.  When you load your form, your report will be displayed in the viewer:

        Dim frm As New frmViewer()
        frm.Show()


0
 

Author Comment

by:SteveB2175
ID: 19600746
I'm running Visual Studio 2005 Standard Edition, and Crystal Reports does not appear on the Add New Item dialog.

Do I need to do something special to make CR available, or does it require an upgrade to a higher version of Visual Studio ?

I would happily implement your solution if CR were available.
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:SteveB2175
ID: 19600891
I've researched this, and it appears that VS standard edition does not include Crystal reports.
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19601468
Oh, bummers.  Sorry.
0
 

Author Comment

by:SteveB2175
ID: 19609857
So, if I were to upgrade Visual Studio, does CR seamlessly integrate into my project and distribute with new publications as the Reportviewer does ?
0
 

Author Comment

by:SteveB2175
ID: 19664799
OK VBRocks, I got approval to purchase VS Pro !!

Thanks for your help.
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19665308
Oh, your going to love it!  VS Pro Rocks!

Just 1 note, when you create a project that uses Crystal Reports, and then get ready to deploy it,
Create a Setup Project for the program, and then add the Crystal Reports Merge Module for VS 2005.
And then run the setup program on every computer that will use your program.  The installer will
install Crystal's merge modules for you.

It's a cynch to add them to the installer, just do the following:
    Right-Click on the Setup Project,
    Click Properties
    Click the Pre-Requisites button.
    Check Crystal Reports for .NET Framework 2.0.
    Click OK, then OK again to close the properties window.

You should be good to go.
0
 

Author Comment

by:SteveB2175
ID: 19665509
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 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