none
Binding dynamic dataset to Report Viewer RRS feed

  • Question

  • Hi,

    I have followed the code from the following link and instead of List collection I have bind the Dataset as a datasource, the datasource cannot be bind in the viewer.

    Reference Link:  http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4bbb9baf-6b0c-4a9f-a81e-6597a275338e/

    Please advice.

    I have done the following approach to view reports dynamically in the report viewer

    1. I have created a rdlc file using a dummy schema.
    2. I have followed your code to initialize the report viewer.
    3. Instead of List collection I have bind the dataset as a datasource.

    Please find the attached code.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.ReportingServices;
    using Microsoft.Reporting;
    using Microsoft.Reporting.WinForms;
    using System.Data;
    using HoneyWell.PMTool.BusinessFacade;
    using HoneyWell.PMTool.Logging; 
    
    namespace HoneyWell.PMTool.WPFWindowsClient
    {
        /// <summary>
        /// Interaction logic for TestPage.xaml
        /// </summary>
        public partial class TestPage : Page
        {
    
            private System.Windows.Forms.BindingSource ProductBindingSource;        
    
            HoneyWell.PMTool.BusinessFacade.Report objReport;
    
            public TestPage()
            {
                InitializeComponent();
                PrepareReport();
            }
    
            /// <summary>
            /// 
            /// </summary>
            private void PrepareReport()
            {
                
                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
    
                this.ProductBindingSource = new System.Windows.Forms.BindingSource();                        
                 
                ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).BeginInit();
                
                this.viewerInstance.LocalReport.ReportPath = @"C:\Documents and Settings\E446542\e446542_view\PMTool\SourceCode\WPFPMTool\Preventative Maintenance Tool\HoneyWell.PMTool.Report\Completed Task Report.rdlc";
                reportDataSource1.Value = this.ProductBindingSource;
    
                this.viewerInstance.LocalReport.DataSources.Add(reportDataSource1);
                this.viewerInstance.LocalReport.ReportEmbeddedResource = "HoneyWell.PMTool.Report.Completed Task Report.rdlc";
                this.viewerInstance.Location = new System.Drawing.Point(89, 119);
    
                ((System.ComponentModel.ISupportInitialize)(this.ProductBindingSource)).EndInit();
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void viewerInstance_ZoomChange(object sender, ZoomChangeEventArgs e)
            {
            }
    
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                objReport = new HoneyWell.PMTool.BusinessFacade.Report();
    
                DataSet ds = objReport.GetCompletedTaskInfo();
    
                ds.DataSetName = "Completed_Task_List";
    
                this.ProductBindingSource.DataSource = objReport.GetCompletedTaskInfo();
    
                this.viewerInstance.RefreshReport();
            }   
        }
    }
    


    Thanks,
    Malarvannan M
    Monday, June 1, 2009 11:06 AM

Answers

  • Hi Malarvannan,

    The primary problem is you give the ReportViewer a ReportDataSource, but you don't provide the ReportDataSource with all the information it needs.

    ReportDataSource is the bridge from your data to your report. So it needs the actual data, which you give it. But it also needs to know the name of the dataset in the report this data corresponds to.

    Your report has a dataset inside of it, that lets the report know what the data will look like. It has a name assigned to it. If you look at your RDLC file in a standard text editor, you will find the dataset name around here:

      <DataSets>
        <DataSet Name="DataSet1_Person">
          <Fields>
            <Field Name="id">
              <DataField>id</DataField>
              <rd:TypeName>System.Int32</rd:TypeName>
            </Field>
            <Field Name="Name">
    

    That name of the dataset needs to be given to the ReportDataSource. Like

    reportDataSource1.Name = "DataSet1_Person"
    That is the major part that is missing in your code. Add in the dataset name and see what you get. Post back here if there are still problems.


    You also don't need to use both ReportPath and ReportEmbeddedResource, just one is needed. If you use ReportEmbeddedResource, then the report has to be compiled into your assembly.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 1, 2009 6:21 PM

All replies

  • Hi Malarvannan,

    The primary problem is you give the ReportViewer a ReportDataSource, but you don't provide the ReportDataSource with all the information it needs.

    ReportDataSource is the bridge from your data to your report. So it needs the actual data, which you give it. But it also needs to know the name of the dataset in the report this data corresponds to.

    Your report has a dataset inside of it, that lets the report know what the data will look like. It has a name assigned to it. If you look at your RDLC file in a standard text editor, you will find the dataset name around here:

      <DataSets>
        <DataSet Name="DataSet1_Person">
          <Fields>
            <Field Name="id">
              <DataField>id</DataField>
              <rd:TypeName>System.Int32</rd:TypeName>
            </Field>
            <Field Name="Name">
    

    That name of the dataset needs to be given to the ReportDataSource. Like

    reportDataSource1.Name = "DataSet1_Person"
    That is the major part that is missing in your code. Add in the dataset name and see what you get. Post back here if there are still problems.


    You also don't need to use both ReportPath and ReportEmbeddedResource, just one is needed. If you use ReportEmbeddedResource, then the report has to be compiled into your assembly.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, June 1, 2009 6:21 PM
  • Hi,

    I have sucessfully created reports with WPF, SQL Server 2005 Express edition and dynamically bind the dataset in to the generated RDL file.

    Thanks for your wonderful support.

    Thanks,
    Malarvannan M
    Monday, June 8, 2009 1:15 PM
  • Hola Malarvannan,

    Excelente informacion, me ayudaste a resolver un problema que tenia desde hace una semana, muchas gracias.

    Saturday, June 18, 2011 7:22 PM
  • You might take a look at www.rptgen.com

    Thanks

     

    Saturday, July 2, 2011 4:47 PM