Am I using this thing right? RRS feed

  • Question

  • I have a Forms app in C#. Environment is Visual Studio 2008 Pro under XP SP2.


    Here's the plan:

    1) Use LINQ to SQL to execute a stored procedure and return an initial set of data (DataSet_SP).
    2) Perform some application logic on the initial data to produce a second set of data (DataSet_Report).
    3) Display a Report built from DataSetReport.
    Part 1 is fine; LINQ is cool.
    Part 2 is fine. I created a typed dataset and at runtime I create an instance of it that I populate with the result of the operations I'm doing on DataSet_SP.
    Part 3 eludes me. I cannot figure out how to get the data into the report.
    In design mode I associated my report with DataSet_Report and laid it out the way I wanted. 
    At runtime, after creating and populating an instance of DataSet_Report, I create a ReportDataSource that points to the (one and only) table in that instance. I then add that DataSource to the report via ReportViewer.LocalReport.DataSources.Add(source).
    I can look in the debugger and verify that the report's count of data sources is now two (presumably, the first is the empty default it was mated with in the designer). I can verify that the source I just added contains data. However, my report is completely devoid of data. All I can see are the static elements I laid out in the report designer.
    What am I doing wrong here? Is this even the correct way to go about it?
    Tuesday, March 25, 2008 7:58 PM

All replies


    Ok, well it seems if I go into the designer-generated code and disconnect the first datasource then it works.



    // reportViewer1


    reportDataSource2.Name = "DataSetReport_Table1";

    reportDataSource2.Value = this.Table1BindingSource;

    //this.reportViewer1.LocalReport.DataSources.Add(reportDataSource2); -- comment this part out


    So now I can use my typed dset to lay out the report and tell it what fields to expect and at runtime I can populate it with data that comes on the fly.


    But surely there's a better way to do this than by commenting out the designer code?

    Tuesday, March 25, 2008 8:27 PM