Dynamic RDLC generation question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronicard
    New Member
    • Dec 2006
    • 3

    Dynamic RDLC generation question

    I'm a newbie to the messageboard, but I'm wondering if any of you gurus have tried to do the following before? I'm developing a custom reporting solution as part of a web application for a corporate client. One of the required features is a user-defined reporting (UDR) solution, but we cannot use ReportBuilder because their corporate firewalls prohibit ActiveX controls. Therefore, I have a wizard-style ASP.NET and C# interface that essentially allows them to go through and select the filtering parameters, fields, etc.

    At the end of all that, I have generated the SQL string and I have to dynamically generate the RDLC code for this new UDR report. I have that part working and I have gone through by hand to verify that the code my rdlcGenerator is producing "appears" to be correct. (As an aside, I have opened the generated .rdlc files from within Visual Studio as well to confirm that they at least appear correct). I actually found a couple of examples on the net that helped me with the generation portion of the code. However, here's my problem:

    Now that I have the new local report template that I generated, I've been unable to get it to run the actual report. I get the following error when I try to make the reportViewer display the report:
    A data source instance has not been supplied for the data source 'DataSet1'.

    I'll include a section of the RDLC file here to show the generic names I built into the report template:

    <DataSources>
    <DataSource Name="DataSourc e1">
    <ConnectionProp erties>
    <DataProvider>S QL</DataProvider>
    <ConnectString> Server=.;Databa se=fms_comm;Use r ID=usr;password =pwd;</ConnectString>
    <IntegratedSecu rity>true</IntegratedSecur ity>
    </ConnectionPrope rties>
    </DataSource>
    </DataSources>
    <DataSets>
    <DataSet Name="DataSet1" >
    <Query>
    <DataSourceName >DataSource1</DataSourceName>
    <CommandType>Te xt</CommandType>
    <CommandText>se lect name as 'Name' from view_DEALER_DIS PLAY</CommandText>
    <Timeout>90</Timeout>
    </Query>
    <Fields>
    <Field Name="Name">
    <DataField>Name </DataField>
    </Field>
    </Fields>
    </DataSet>
    </DataSets>

    And here is the c# code where I'm trying to add to add the datasource dynamically:

    this.reportView er1.ProcessingM ode = ProcessingMode. Local;
    this.reportView er1.LocalReport .ReportPath = _RDLfileName;
    DataTable dt;
    dt = DataAccess.getD ataTable(sqlTex t, null, false);
    // the above line returns a valid dataTable that I have confirmed has records
    TextReader re = File.OpenText(_ RDLfileName);

    ReportDataSourc e rds = new ReportDataSourc e();
    rds.Name = "DataSource1_Da taSet1";
    rds.Value = dt;
    this.reportView er1.LocalReport .DataSources.Ad d(rds);
    this.reportView er1.LocalReport .LoadReportDefi nition(re);
    this.reportView er1.LocalReport .Refresh();
    re.Close();

    If any of you guys can point out the error of my ways, I will GLADY acknowledge you as Guru Extraordinaire. :)
  • dshipe
    New Member
    • Aug 2007
    • 2

    #2
    At the end of all that, I have generated the SQL string and I have to dynamically generate the RDLC code for this new UDR report."


    Here is an alternate method for generating an RDLC....
    http://csharpshooter.b logspot.com/2007/08/generate-rdlc-dynamically-for-vs-2005.html

    Comment

    • dshipe
      New Member
      • Aug 2007
      • 2

      #3
      The easiest way to generate a simple RDLC from a dataset is transform the schema xml into the RDLC.

      The basic idea is to build rather generic RLDC file off a DataSet. You can then bind both the DataSet and the RDLC to a ReportViewer control and get your report. I generate the RDLC by transforming the DataSet XML schema into a RDLC file via and XSLT transform.

      Here is a website showing the C# code and the XSLT...

      http://csharpshooter.b logspot.com/2007/08/revised-dynamic-rdlc-generation.html

      Comment

      Working...