Because the report is complex and involves data from multiple tables, and the report format is complex, all the data required for the report is calculated during design and then saved to dataset, dataset contains six tables, and then writes dataset to the XML file. Then, the XML file is used as the design basis for the report data fields.
// Display the report. Click ()
Reportquery RQ = new reportquery ();
Dataset DS = new dataset ();
DS = RQ. getreportdata (jyjxsbm_list, sfzh_list); // obtain report data
DS. writexml (@ "C: \ report. xml"); // write report data to the XML file
Fmreportforms fm = new fmreportforms ();
FM. Show ();
// Report load ()
Samspoint. Report. SDAS. crystalreport4 Cr = new samspoint. Report. SDAS. crystalreport4 ();
Dataset DS = new dataset ();
DS. readxml (@ "C: \ report. xml ");
Cr. setdatasource (DS );
This. crystalreportviewer1.reportsource = CR;
Errors may occur when running: Unknown query engine errors and query engine errors. Note that not all situations will cause errors!
Later I thought about why I had to write the XML file and then read the XML file to the dataset. Isn't that the case? In fact, the original idea was that since XML was the data source, we had to read the XML file and then use the read data as the data source! A big mistake !! When designing a report, the report field designed from the XML file is actually just a template, as long as the report data source (Cr. setdatasource (DS);) is consistent with the data source in the design phase.
Why is an error reported? Because some fields are empty when writing an XML file, they are not in the XML file. As a result, errors are inevitable!
// Display the report. Click ()
Reportquery RQ = new reportquery ();
Dataset DS = new dataset ();
DS = RQ. getreportdata (jyjxsbm_list, sfzh_list); // obtain report data
Fmreportforms fm = new fmreportforms ();
FM. reportdata = Ds;
FM. Show ();