Having trouble binding a ReportViewer to a DataSet

Posted on 2007-07-31
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")))

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 !!
Question by:SteveB2175

    Author Comment

    As an update, I added the following lines:

     Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "WindowsApplication1.rptCoa.rdlc"

    Ahead of

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

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

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

    Accepted Solution

    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

            '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()


    Author Comment

    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.

    Author Comment

    I've researched this, and it appears that VS standard edition does not include Crystal reports.
    LVL 27

    Expert Comment

    Oh, bummers.  Sorry.

    Author Comment

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

    Author Comment

    OK VBRocks, I got approval to purchase VS Pro !!

    Thanks for your help.
    LVL 27

    Expert Comment

    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.

    Author Comment


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    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 (…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, 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…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    732 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

    18 Experts available now in Live!

    Get 1:1 Help Now