none
Calling a stored procedure and setting the result to the Reports data source RRS feed

  • Question

  • I am working on a report that needs to display Schedule information to a user. The report calls into a stored procedure, which accept two parameters, then set the result of the query to the ReportDataSource. Unfortunately, there is data in the dataset after the call into the stored procedure is made, but the data never gets into the report. Below is my code... can someone help me out with this issue?

    Thanks!

    Craig

     

    TList<Schedule> scheduleList = new TList<Schedule>();

     

    this.reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;

    Microsoft.Reporting.WinForms.

    LocalReport rep = reportViewer1.LocalReport;

    rep.ReportPath =

    "SampleReport2.rdlc";

     

    DataSet ds = new DataSet();

     

    DateTime fromDate = new DateTime(2010, 1, 1);

     

    DateTime toDate = new DateTime(2010, 9, 1);

    ds =

    DataRepository.ScheduleProvider.GetByDateRange(fromDate, toDate);

     

     

     

    Microsoft.Reporting.WinForms.

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

     

    schedulerSource.Name =

    "TotalCareDataSet_RSP_Schedule_GetByDateRange";

    schedulerSource.Value = ds;

    rep.DataSources.Add(schedulerSource);

     

    this.reportViewer1.RefreshReport();

    Thursday, September 9, 2010 6:29 PM

Answers

  • Craig,

    Based on my test, ReportDataSource.Value does not accept a DataSet object, instead it can accept a DataTable object or an object implementing IEnumerable interface, http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportdatasource.value(v=VS.90).aspx.

    So I think that this line of your code "schedulerSource.Value = ds;" should be changed to "schedulerSource.Value=ds.Tables[0];" first.

     

    In addition, you need to make sure that:

    1. The report data source name is same as the datasource_name in the section "<DataSets><DataSet Name=datasource_name>" in your report's XML source code.

    2. The columns names in the datatable in your dataset fully match the columns names defined in your report.

    If the above are satisfied but the report still displays blank, the problem should be related to the already defined DataSources in your local report. There might be a duplicated blank dataset with the same name in the data source collection. In this case, there are some methods you can try:

    1. Clearing the data source collection defined in your reportviewer before you add the report datasource. For example:

          Microsoft.Reporting.WinForms.ReportDataSource rs = new Microsoft.Reporting.WinForms.ReportDataSource();
          rs.Name = "TestDataSet1_Employees";
          rs.Value = ds1.Tables[0];
          this.reportViewer1.LocalReport.DataSources.Clear();
          this.reportViewer1.LocalReport.DataSources.Add(rs);
          this.reportViewer1.RefreshReport();
    

    2. Insert or your data source to the 0 index position in the data source collection:

          Microsoft.Reporting.WinForms.ReportDataSource rs = new Microsoft.Reporting.WinForms.ReportDataSource();
          rs.Name = "TestDataSet1_Employees";
          rs.Value = ds1.Tables[0];
    
          this.reportViewer1.LocalReport.DataSources.Insert(0,rs); //or this.reportViewer1.LocalReport.DataSources[0]=rs;
          this.reportViewer1.RefreshReport();
    

    3. Remove the reportviewer control from your windows form and drag a new one to your windows form. Do not set anything just leave a clear setting. Then you set the processing model and local report's report path with code.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Craigster Monday, September 13, 2010 12:19 PM
    Friday, September 10, 2010 10:54 AM
    Moderator