4

I want to know how can i create an crystal report from a XML (XML is from a Web Service), I read in some tutorials that it needs to locate the file and drag the fields in the report, but how about a XML from a Web Service?

Here is the code how I get the XML from a Web Service

  var doc = XDocument.Parse(trx.GetCardTrx("xxxxx", "xxxx", "xxx", "", dateTimePicker1.Text, dateTimePicker2.Text, "", "", "", "", "", "", "", "", "", "", "", "FALSE", "", "", "", "", "", "", "", "", "", "", ""));
MessageBox.Show(doc.ToString());

So this code return this kind of values (From MessageBox.Show(doc.ToString())

enter image description here

And here is the code for the selected values that should be in the report

var summary = from r in doc.Descendants("TrxDetailCard") 
                      select new 
                      {
                          Account_Type = r.Element("Account_Type_CH").Value,
                          Captured = r.Element("Captured").Value,
                          Trans_Type_ID = r.Element("Trans_Type_ID").Value,
                          Acct_Num_CH = r.Element("Acct_Num_CH").Value,
                          Tip_Amt_MN = r.Element("Tip_Amt_MN").Value,
                          Total_Amt_MN = r.Element("Total_Amt_MN").Value,
                          Date_DT = r.Element("Date_DT").Value,
                      };

And What I want to happen is that to create a report using Crystal Reports with this values, not all values. Selected values only. How can I possibly do this? Any ideas will be a big help Thank you :D

GrayFullBuster
  • 1,033
  • 3
  • 18
  • 23

1 Answers1

2

This has not been tested but can you try something like the following

using System.Xml;
using System.Xml.Linq;

var doc = XDocument.Parse(trx.GetCardTrx("xxxxx", "xxxx", "xxx", "", dateTimePicker1.Text, dateTimePicker2.Text, "", "", "", "", "", "", "", "", "", "", "", "FALSE", "", "", "", "", "", "", "", "", "", "", ""));

  var data = new DataSet();
  var context = new XmlParserContext(null, new XmlNamespaceManager(new NameTable()), null, XmlSpace.None);
  var reader = doc
  data.ReadXml(reader);

  var report = new ReportDocument();

  report.SetDataSource(data);
  this.crystalReportViewer1.ReportSource.ReportSource = report;

The Idea in theory should work but you can reference something similar from this link XML-based Crystal Report not updating child objects on refresh

Community
  • 1
  • 1
MethodMan
  • 18,625
  • 6
  • 34
  • 52