Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8451

Re: Change datasource for xml and xsd in runtime

$
0
0

Hi Andrew,

 

SO I went back and had a second look at this question and my code snippets and I can simplify it even more.

 

Your first example you were loading the XML data into a Dataset and using an XSD file for the structure:

 

            System.Data.DataSet reportData = new System.Data.DataSet();

            reportData.ReadXml(xmlFile);

            ReportDocument reportDoc = newReportDocument();

            reportDoc.Load(rptFile);

// comment this line out and it should work            reportDoc.DataSourceConnections[0].SetConnection(xsdFile, "", false);

            reportDoc.SetDataSource(reportData);

 

What you should do to generate the XML/XSD is use this line so it it's all in  the xml file

 

"c:\\sc.xml", XmlWriteMode.WriteSchema);

 

Then your code will work, as long as your remove the one line.

 

If you want to read the XML file directly then the below code will work and you are not limited to a Dataset memory limitation.

 

Try this:

 

try
{
    foreach (CrystalDecisions.CrystalReports.Engine.Table rptTable in rpt.Database.Tables)
    {
        try
        {
            rptTable.Location = @"C:\Datafolder\" + rptTable.Location + ".xml";
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex.Message);
        }


    }
}
catch (Exception ex)
{
    MessageBox.Show("ERROR: " + ex.Message);
}

 

 

This assumes you are using the crdb_ADOPlus driver.

 

Don


Viewing all articles
Browse latest Browse all 8451

Trending Articles