none
C# and rdlc RRS feed

  • Question

  • I am currently looking at moving away from crystal reports and using Microsoft Reporting in the flavor of the rdlc format at the files need to be portable and easily added to the actual application.  In crystal reports and I can easily add the rpt file to a file server and have the users open the application and then point the report file, in the backend the report is opened, assigned the connection string and then passed to the viewer to generate the report. 

    The MS offering for this seem a bit move involved and I believe the process needs to be: upload the rdlc and xsd file to the file server and in code load the schema, populate the dataset, assign the reportdatasource, assign the report to the viewer and set the datasources and finally refresh the report.

    Now my question becomes how can I populate the dataset from the query that is stored in the xsd data?  My code so far is:

    DataSet ds = new DataSet();

    ds.ReadXmlSchema(@"C:\xx\Company_People.xsd");

               

    Microsoft.Reporting.WinForms.ReportDataSource rds =

    new Microsoft.Reporting.WinForms.ReportDataSource("CP", ds.Tables[0]);

               

    reportViewer1.LocalReport.ReportPath = @"C:\xx\Report1.rdlc";

    reportViewer1.LocalReport.DataSources.Clear();

    reportViewer1.LocalReport.DataSources.Add(rds);

    reportViewer1.LocalReport.Refresh();

               

    this.reportViewer1.RefreshReport();

    Here is what seemingly is the relevant section from the xsd file.

    Thanks

    Jeremy

    <Tables>

              <TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="DataTable1TableAdapter" GeneratorDataComponentClassName="DataTable1TableAdapter" Name="DataTable1" UserDataComponentName="DataTable1TableAdapter">

                <MainSource>

                  <DbSource ConnectionRef="ConnectionString (Settings)" DbObjectType="Unknown" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="false" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="false" UserGetMethodName="GetData" UserSourceName="Fill">

                    <SelectCommand>

                      <DbCommand CommandType="Text" ModifiedByUser="true">

                        <CommandText>SELECT        COMPANIES.CID, COMPANIES.NAME, PEOPLE.PID, PEOPLE.FIRSTNAME, PEOPLE.LASTNAME, PEOPLE.MIDDLENAME, PEOPLE.DOB,

                             PEOPLE.GENDER

    FROM            { oj COMPANIES LEFT OUTER JOIN

                             PEOPLE ON COMPANIES.CID = PEOPLE.COMPANY }

    WHERE        (COMPANIES.CID = 9) OR

                             (COMPANIES.CID = 10)</CommandText>

                        <Parameters />

                      </DbCommand>

                    </SelectCommand>

                  </DbSource>

                </MainSource>

                <Mappings>

                  <Mapping SourceColumn="CID" DataSetColumn="CID" />

                  <Mapping SourceColumn="NAME" DataSetColumn="NAME" />

                  <Mapping SourceColumn="PID" DataSetColumn="PID" />

                  <Mapping SourceColumn="FIRSTNAME" DataSetColumn="FIRSTNAME" />

                  <Mapping SourceColumn="LASTNAME" DataSetColumn="LASTNAME" />

                  <Mapping SourceColumn="MIDDLENAME" DataSetColumn="MIDDLENAME" />

                  <Mapping SourceColumn="DOB" DataSetColumn="DOB" />

                  <Mapping SourceColumn="GENDER" DataSetColumn="GENDER" />

                </Mappings>

                <Sources />

              </TableAdapter>

            </Tables>

            <Sources />

          </DataSource>

    • Moved by Caillen Monday, March 24, 2014 9:37 AM
    Sunday, March 23, 2014 9:00 PM

All replies

  • Hi

    You can find a simple example how to create and use rdlc report un asp.net in link below.

    http://kishor-naik-dotnet.blogspot.in/2011/06/aspnet-rdlc-report-in-aspnet.html?m=1

    Hope it will help.


    Ashish Pandey

    Monday, March 24, 2014 5:48 AM
  • Hi kcusscam,

    Welcome to post in MSDN forums!

    Visual C# forum doesn't provide support for Report Controls questions, I'm moving your question to Visual Studio Report Control forum for better responses.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 24, 2014 9:38 AM
  • Thanks for the link but it actually does not help.  In the provided example the dataset is populated from a query done in compiled code.  What I need to do is distribute the report and assumedly the xsd file because the query will be unknown and defined when the report is written.In the generated xsd file the query exists in what looks like a object expressed in xml.  My question is how can I reconstruct the defined object from the xsd file so the query can be executed and repopulate the dataset.  I know I will need to create a new odbc connection as the software actually has the connections string data.

    Thanks

    Jeremy

    Wednesday, March 26, 2014 1:29 AM