none
How to display report data using a data table populated with a store procedure ?? RRS feed

  • Question


  • I created a Dataset where all the tables' sources are from various Store Procedures.  In the dataset I can preview the data just find when I click on the preview command.  The DB is a SQL Express 2005 and using VS 2008  c#.  

    The problem is I can't get the new report window to display any data when I assign it the same names as I can easily view in preview in the dataset.   My question is does this Report tool only work with database tables and not Store procedures or am I missing something in my assignments.   I am starting to think my only option is to just return the data in grids and use that as the reporting section.

    Thanks
    K


    Here is my code..

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

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

    reportDataSource.Name = "DBReporting";
    reportDataSource.Value =
    this.spNameTagListBindingSource;
    rv.LocalReport.DataSources.Add(reportDataSource);
    rv.LocalReport.ReportEmbeddedResource =
    "DBReportingTool.NameTagList.rdlc";
    rv.RefreshReport();

    Monday, March 16, 2009 8:52 AM

All replies

  •  hi, you can definately do what your attempting to do. I think you just need a little help.

    I look at your code, and it seems fine, except for the datasource.

    what is that?

    Maybe you could make a slight change to your code like this.


    DataTable reportTable = this.spNameTagListBindingSource;

    reportDataSource.Value = reportTable;


    I'm not sure what your spName.... object is, but reports will accept more then just a Datatable as a datasource, and hence I believe you might not be catching your error.  

    Seems like you've got everything correct except for actually handing the values to the report correctly.


    Living my life at 123mph in 11.15 seconds
    Monday, March 16, 2009 2:02 PM
  • Blast -- thanks for the reply.

       The error I get is "A data source instance has not been supplied for the data source "DBreporting_spNameTagList"

       DBReporting is the name of the dataset
       SpNameTagList is the table created in the dataset based on a store procedure called spNameTaglist
       spNameTagListBindingSource is the binding source object created in the window after creating the report.

        I noticed there is not an tableAdaptor created when create a report based on a db table.  I updated the reportDataSouce to be the binding object and the table object but same error as above.   Do I need to manually populate the dataset somehow?

    Thanks
    K


    reportDataSource.Name = "DBReporting.spNameTagListBindingSource";
    reportDataSource.Value = "dbo.spNameTagList";

    Monday, March 16, 2009 9:12 PM
  • ok first  if that's the name it's lookiing for then that's the name of your report data source


    reportDataSource.Name = "DBreporting_spNameTagList";

    The datasource name is auto-generated when you attach it to the report. You can edit it if you want, but in this case you just need to change it to match what it's looking for.

    as you can see it named the datasource as   [Datasetname]_[TableName]

    to see what a report has for datasources, and what they are named. When you are in design mode for your report, there should be a drop-down menu option at the top that says Report I believe. and it has a choice for datasources.

    Now,  the datatable itself has to be populated before you give it to the report.  If you don't have anything triggering the Fill method on that adapter, then your gonna have to trigger it yourself.

    Try changing your reportname first that way you get past the first error.
    Living my life at 123mph in 11.15 seconds
    Monday, March 16, 2009 9:17 PM
  • I think that is my problem - filling the data table from the Store Procedure as I can see the blank report.  Unlike a table from a DB table - there is no adaptor generated, just a binding source.  And from code - I do not see the fill method as a option on the bindingSource object.    I am alittle confused on how to do populate the Store Proc table.

    I tried something like this.


    IDataReader dreader;
    dreader = DBReporting.CreateDataReader();
    DBReporting.spNameTagList.Load(dreader);

    Monday, March 16, 2009 9:35 PM
  • eh, well Data Access is something based mostly on how you have things setup heh.

    I encourage most people when dealing with doing local reporting, to think of getting data as seperate from showing it on the report.

    Local reports will accept whatever you give it, so long as the datasource name matches what it expects.

    So, the question is, what's the best way to get data back from your database, and drop it into an object.  Well a Datatable in this case.

    In my solutions I don't even use datasets, I only use them to design the reports, but I don't actually include one in my projects.


    the dataset, is not directly linked to the report, once you design a report, it saves it's configuration within the .rdlc file.  So essenctially, whatever method you want to use to fire off that stored procedure and return the data will work. 


    Living my life at 123mph in 11.15 seconds
    Monday, March 16, 2009 9:49 PM
  • Blast.

        That was it, I needed to manually populate that data table and now I can see data in the report.  Thanks for the help.

    K.


    SqlConnection mySqlConnection = new SqlConnection(sconn);
    SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
    SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
    mySqlCommand.CommandText =
    "EXECUTE spNameTagList";
    mySqlDataAdapter.SelectCommand = mySqlCommand;
    mySqlConnection.Open();
    mySqlDataAdapter.Fill(
    DBReporting.spNameTagList);

    Monday, March 16, 2009 10:02 PM
  • cool, glad I could help. 
    Living my life at 123mph in 11.15 seconds
    Tuesday, March 17, 2009 1:03 PM