locked
Set Xml DataSource of rdlc in code RRS feed

  • Question

  • Hi,

    I created a report with Report Builder, here is the DataSource and DataSets Xml part:

    <?xml version="1.0" encoding="utf-8"?>
    <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
     <DataSources>
      <DataSource Name="CFD">
       <ConnectionProperties>
        <DataProvider>XML</DataProvider>
        <ConnectString>http://localhost/FacturasElectronicas/2.xml</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
       </ConnectionProperties>
       <rd:DataSourceID>8c434529-d6fb-4607-aaa3-aa6dc1c470b8</rd:DataSourceID>
       <rd:SecurityType>Windows</rd:SecurityType>
      </DataSource>
     </DataSources>
     <DataSets>
      <DataSet Name="DatosCFD">
       <Fields>
        <Field Name="folio">
         <DataField>folio</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="fecha">
         <DataField>fecha</DataField>
         <rd:TypeName>System.DateTime</rd:TypeName>
        </Field>
        <Field Name="serie">
         <DataField>serie</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="formaDePago">
         <DataField>formaDePago</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="anoAprobacion">
         <DataField>anoAprobacion</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="noCertificado">
         <DataField>noCertificado</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="sello">
         <DataField>sello</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="noAprobacion">
         <DataField>noAprobacion</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="calle">
         <DataField>calle</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="subTotal">
         <DataField>subTotal</DataField>
         <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
        <Field Name="total">
         <DataField>total</DataField>
         <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
        <Field Name="noExterior">
         <DataField>noExterior</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="colonia">
         <DataField>colonia</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="localidad">
         <DataField>localidad</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="municipio">
         <DataField>municipio</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="rfc">
         <DataField>rfc</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="estado">
         <DataField>estado</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="nombre">
         <DataField>nombre</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="DomicilioFiscal">
         <DataField>DomicilioFiscal</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="pais">
         <DataField>pais</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="codigoPostal">
         <DataField>codigoPostal</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
       </Fields>
       <Query>
        <DataSourceName>CFD</DataSourceName>
        <CommandText>&lt;Query&gt;
    &lt;ElementPath IgnoreNamespaces="True"&gt;
    Comprobante{@folio,@serie, @anoAprobacion,@noAprobacion,@fecha(date),@sello,@formaDePago,@noCertificado,@subTotal(decimal),@total(decimal)}/Emisor/DomicilioFiscal
    &lt;/ElementPath&gt;
    &lt;/Query&gt;</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
       </Query>
      </DataSet>
      <DataSet Name="ConceptosCFD">
       <Fields>
        <Field Name="cantidad">
         <DataField>cantidad</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="descripcion">
         <DataField>descripcion</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="valorUnitario">
         <DataField>valorUnitario</DataField>
         <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
        <Field Name="importe">
         <DataField>importe</DataField>
         <rd:TypeName>System.Decimal</rd:TypeName>
        </Field>
       </Fields>
       <Query>
        <DataSourceName>CFD</DataSourceName>
        <CommandText>&lt;Query&gt;
    &lt;ElementPath IgnoreNamespaces="True"&gt;
    Comprobante{}/Conceptos{}/Concepto{@cantidad,@descripcion,@valorUnitario(decimal),@importe(decimal)}
    &lt;/ElementPath&gt;
    &lt;/Query&gt;</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
       </Query>
      </DataSet>
      <DataSet Name="ReceptorCFD">
       <Fields>
        <Field Name="rfc">
         <DataField>rfc</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="nombre">
         <DataField>nombre</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="calle">
         <DataField>calle</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="colonia">
         <DataField>colonia</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="localidad">
         <DataField>localidad</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="estado">
         <DataField>estado</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="pais">
         <DataField>pais</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="codigoPostal">
         <DataField>codigoPostal</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="Domicilio">
         <DataField>Domicilio</DataField>
         <rd:TypeName>System.String</rd:TypeName>
        </Field>
       </Fields>
       <Query>
        <DataSourceName>CFD</DataSourceName>
        <CommandText>&lt;Query&gt;
    &lt;ElementPath IgnoreNamespaces="True"&gt;
    Comprobante{}/Receptor/Domicilio
    &lt;/ElementPath&gt;
    &lt;/Query&gt;</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
       </Query>
      </DataSet>
    

    So there are 3 DataSets that use the DataSource named "CFD".

    I need to direct print this report from a proyect... so I did the following:

    Rename the report.rdl to report.rdlc

    Added report.rdlc to the proyect

    To print the report I have this:

    public void Imprimir(System.Xml.XmlDocument DoctoXML)
      {
        LocalReport report = new LocalReport();
        report.ReportPath = @"CFD.rdlc";
    
        report.DataSources.Add(new ReportDataSource("CFD", DoctoXML));
        
        Export(report);
        m_currentPageIndex = 0;
        Print();
      }
    

    Method Imprimir has a parameter of type XmlDocument (DoctoXML). So this is the Xml that I need to use as the DataSource of the report. (also from this XmlDocument was created the <ConnectString>http://localhost/FacturasElectronicas/2.xml</ConnectString>
     file that I used to create the report in Report Builder)

    The process throws this error: "An error occurred during local report processing."

    The InnerException message is "ConceptosCFD". I think that is saying that the DataSet ConceptosCFD was not found....

    If I do this:

     public void Imprimir(System.Xml.XmlDocument DoctoXML)//System.Xml.XmlReader DoctoXML)
      {
        LocalReport report = new LocalReport();
        report.ReportPath = @"CFD.rdlc";
    
        report.DataSources.Add(new ReportDataSource("CFD", DoctoXML));
        report.DataSources.Add(new ReportDataSource("DatosCFD", DoctoXML));
        report.DataSources.Add(new ReportDataSource("ConceptosCFD", DoctoXML));
        report.DataSources.Add(new ReportDataSource("ReceptorCFD", DoctoXML));
        
        
        Export(report);
        m_currentPageIndex = 0;
        Print();
      }
    

    The report prints out but without data, it only shows the report objects (text, tables, lines, etc)

    What am I doing wrong?

    Tnx


    G
    Tuesday, April 5, 2011 7:54 PM

Answers

  • Hi Giber

    Based on the description that you provided, we have following two issues,

    1. If we only specified "CFD" as the ReportDataSource name, it gave "An error occurred during local report processing" error message.
    2. If we added other three DataSet name to ReportDataSource, we can only get report objects.

    If I misunderstood the problem, please let me know.

    Basically, I think we need to use DataSet name while initializing the ReportDataSource instead of the DataSource name "CFD". At this moment, I think you may try follows,

    public void Imprimir(System.Xml.XmlDocument DoctoXML)//System.Xml.XmlReader DoctoXML)
    {
    LocalReport report = new LocalReport();
    report.ReportPath = @"CFD.rdlc";

    report.DataSources.Add(new ReportDataSource("DatosCFD", DoctoXML));
    report.DataSources.Add(new ReportDataSource("ConceptosCFD", DoctoXML));
    report.DataSources.Add(new ReportDataSource("ReceptorCFD", DoctoXML));

    Export(report);
    m_currentPageIndex = 0;
    Print();
    }

    Furthermore, can you please provide the detailed error message as well as the inner exception set that contains more details on the problem to me? This can help us understand the error efficiently.

    Here is a sample for obtaining the inner exception,

    Try
       SOME ACTIONS  <-- Add the code here -->
    Catch e As System.Exception

       Dim inner As Exception = e.InnerException
       While Not (inner Is Nothing)
          MsgBox(inner.Message)
          inner = inner.InnerException
       End While

    End Try

    Thank you.
    Eileen

    • Marked as answer by Challen Fu Wednesday, April 13, 2011 11:05 AM
    Sunday, April 10, 2011 11:28 AM