none
Using MicrosoftReportViewer with a created dataset RRS feed

  • Question

  • I am creating a list of objects in my program that I want to view and print.  My thought was that I would put the objects into a typed dataset, and use a MicrosoftReportViewer to view and print them.

    My problem is (or at least appears to be) that I can't actually set my local variable to be the source of data for the MicrosoftReportViewer object.

    So, what I want to do is
    1.  Create an XSD type.  Edit it to be what I want.  It will have a single table, and that table will have a few fields.  I've done that.  Well call it myxsd.  It's only table will be named myxsdtable.
    2.  Create a report, we'll call it myReport, that displays the contents of a myxsd.  Here's where I might be running into problems.  When I create myxsd, it shows up in the project's Data Sources window.   I create the report, drag a table into the designer pane, and then drag fields from the data sources.
    3.  On the form designer, drag a MicrosoftReportViewer object, and tell it I want to use myReport as the report for the viewer.
    4.  Run my program.  My program has a local variable called mylocalxsd, which is of type myxsd.
    5.  Populate the rows of table myxsdtable within mylocalxsd.
    6.  Use the MicrosoftReportViewer1 object to view the contents of mylocalxsd.  Here is definitely where I have a problem.  I can't figure out where I tell the program that the variable, mylocalxsd, is the actual  object that ought to be used for the data source for MicrosoftReportViewer1.  I always get a blank report with no data, presumably because the "data source" is just a placeholder that doesn't actually connect to real data.

    How do I tell it to use my data, instead of some sort of connection to a SQL server?
    Tuesday, March 16, 2010 6:02 PM

Answers

  • Hello Meadmaker,

     

    Welcome to ADO.NET DataSet forum!

     

    If I understand the issue correctly, you used all the Visual Studio wizards to create the typed dataset, the report and to set the data source of the report to the typed dataset, right?   By default, Visual Studio will auto-generate a local typed dataset object and its corresponding BindingSource and TableAdapter to load the dataset from the database.  

     

    If here we create a local dataset object and it should be the data source for the report, we need to modify the logic of the InitializeComponent method.  Open the form’s designer file, the InitializeComponent should be similar with:

    =====================================================================================

                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();

                this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();

                this.TestDBDataSet = new CSDataSetDataTable.TestDBDataSet();

                this.ParentTableBindingSource = new System.Windows.Forms.BindingSource(this.components);

                this.ParentTableTableAdapter = new CSDataSetDataTable.TestDBDataSetTableAdapters.ParentTableTableAdapter();

                ((System.ComponentModel.ISupportInitialize)(this.TestDBDataSet)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(this.ParentTableBindingSource)).BeginInit();

                this.SuspendLayout();

                //

                // reportViewer1

                //

                reportDataSource1.Name = "TestDBDataSet_ParentTable";

              reportDataSource1.Value = this.ParentTableBindingSource;

                this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);

                this.reportViewer1.LocalReport.ReportEmbeddedResource = "MyProject.Report1.rdlc";

                this.reportViewer1.Location = new System.Drawing.Point(47, 29);

                this.reportViewer1.Name = "reportViewer1";

                this.reportViewer1.Size = new System.Drawing.Size(437, 280);

                this.reportViewer1.TabIndex = 0;

    =====================================================================================

     

    We can set the BindingSource.DataSource to your local dataset object.   Here is a related thread discussing the similar issue for your references, http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/f845d74d-3fbc-4601-bccb-3bb350099d32. 

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, March 17, 2010 4:45 AM
    Moderator

All replies

  • Hello Meadmaker,

     

    Welcome to ADO.NET DataSet forum!

     

    If I understand the issue correctly, you used all the Visual Studio wizards to create the typed dataset, the report and to set the data source of the report to the typed dataset, right?   By default, Visual Studio will auto-generate a local typed dataset object and its corresponding BindingSource and TableAdapter to load the dataset from the database.  

     

    If here we create a local dataset object and it should be the data source for the report, we need to modify the logic of the InitializeComponent method.  Open the form’s designer file, the InitializeComponent should be similar with:

    =====================================================================================

                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();

                this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();

                this.TestDBDataSet = new CSDataSetDataTable.TestDBDataSet();

                this.ParentTableBindingSource = new System.Windows.Forms.BindingSource(this.components);

                this.ParentTableTableAdapter = new CSDataSetDataTable.TestDBDataSetTableAdapters.ParentTableTableAdapter();

                ((System.ComponentModel.ISupportInitialize)(this.TestDBDataSet)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(this.ParentTableBindingSource)).BeginInit();

                this.SuspendLayout();

                //

                // reportViewer1

                //

                reportDataSource1.Name = "TestDBDataSet_ParentTable";

              reportDataSource1.Value = this.ParentTableBindingSource;

                this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);

                this.reportViewer1.LocalReport.ReportEmbeddedResource = "MyProject.Report1.rdlc";

                this.reportViewer1.Location = new System.Drawing.Point(47, 29);

                this.reportViewer1.Name = "reportViewer1";

                this.reportViewer1.Size = new System.Drawing.Size(437, 280);

                this.reportViewer1.TabIndex = 0;

    =====================================================================================

     

    We can set the BindingSource.DataSource to your local dataset object.   Here is a related thread discussing the similar issue for your references, http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/f845d74d-3fbc-4601-bccb-3bb350099d32. 

     

    If you have any questions, please feel free to let me know.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, March 17, 2010 4:45 AM
    Moderator
  • Hi Meadmaker,

     

    I am writing to check the status of the issue on your side.  Would you mind letting me know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, March 22, 2010 1:19 AM
    Moderator