Skip to Content
0
Former Member
Sep 24, 2008 at 03:26 PM

Native XML Driver & .NET Application

60 Views

I found this thread: https://www.sdn.sap.com/irj/sdn/businessobjects-sdk-forums the poster is asking exactly what I need to know, but the suggestions posted aren't working for me.

I'm developing in CR XI R2 SP 4, Visual Studio 2005. In Crystal Reports, I select Native XML Driver, point to my XML file (named MasterXML.xml) and my XSD file. Build the Report & Save. In .NET, I can launch the report with the following code and it works great:

public partial class Form1 : Form
    {
        private ReportDocument nestReport;

        public Form1()
        {
            InitializeComponent();

            this.Load += new EventHandler(Form1_Load);            
        }

        void Form1_Load(object sender, EventArgs e)
        {
            nestReport = new ReportDocument();

            string appPath = @"C:\_NET_2_0_Projects\myCRViewer\myCRViewer";
            string RPT_Path = appPath + @"\Reports\New_ne.rpt";                    

            nestReport.Load(RPT_Path);

            crystalReportViewer1.ReportSource = nestReport;
        }
    }

Now I've taken MasterXML.xml and copied it, renamed it to MasterXML1.xml. I changed several of the element values, but it still conforms to the same schema as the original MasterXML.xml. How do I launch the report with a new XML Source?

public partial class Form1 : Form
    {
        private ReportDocument nestReport;

        public Form1()
        {
            InitializeComponent();

            this.Load += new EventHandler(Form1_Load);            
        }

        void Form1_Load(object sender, EventArgs e)
        {
            nestReport = new ReportDocument();

            string appPath = @"C:\_NET_2_0_Projects\myCRViewer\myCRViewer";
            string RPT_Path = appPath + @"\Reports\New_ne.rpt";
            string XML_Path = appPath + @"\Reports\MasterXML1.xml";            

            nestReport.Load(RPT_Path);

            DataSet dataSet = new DataSet();
            dataSet.ReadXml(XML_Path);            

            //Below does not work
            nestReport.Database.Tables[0].SetDataSource(dataSet);

            //Below also does not work
            //nestReport.SetDataSource(dataSet);

            crystalReportViewer1.ReportSource = nestReport;
        }
    }

No matter what I do, I can not switch the XML datasource.

I'm trying to avoid the ADO.NET dataset route totally because I want my .net viewer to take a RPT location, and an XML location as parameters, and launch the report, with no knowledge of the reports contents.

I've seen a note that pertains to RAS and I've seen a note pertaining to VB 6. But not one for .NET Can someone help? Thanks.