Ask a questionAsk a question
 

QuestionDynamically create dataset for Report

  • Saturday, May 10, 2008 5:10 PMAFdotNET Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am new at ReportViewer, and have looked at many examples and tutorials, but I still have a nagging issue. I am writing an app in which I need to create a dataset completely at run time.  The question is: can you bind this runtime dataset to the rdlc file at runtime?  All examples I've seen involve defining the dataset at design time, then dragging the fields from a table to a report item, such as a table.  Is it possible to do all of this in VB code?

    Thanks for your help.

All Replies

  • Sunday, May 25, 2008 2:27 PMChris5gd Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The short answer is 'yes'.  Although it's not as nice as it will be one day when there's a proper class library that lets us do the whole thing programmatically if we want.

    The issue is this: the dataset generated at run time has to match the one used when defining the report.

    Our workflow at present (using VS08) is this:

    - generate a suitable dataset
    - create an XSD from it
    - add the XSD as a datasource in Visual Studio
    - drag and drop fields from it to the report; save the report

    Once this is done, you can throw away the XSD file, since its information is now embedded in the .rdlc file.

    Then at run time, provided you generate an identically structured dataset, you can bind it to the report in code.

    It's not all that pretty, and if anyone has a better way, I'd be very grateful to hear it.  I'm something of a beginner at this too.