Show xml result of WebSerive in DataGridView

Viewed 52

I write an application that checks serial number history with Windows From with my company web-service. The results returned from the Web-service are as follows:

<NewDataSet>
<TestHistory>
    <StartTime>2021-01-09T17:37:38+07:00</StartTime>
    <StopTime>2021-01-09T17:37:42+07:00</StopTime>
    <TestStatus>P</TestStatus>
    <MachineName>HCMINGAOI06_B</MachineName>
    <Operator />
    <StepOrTestName>AOI_BSI</StepOrTestName>
    <FailureLabel />
    <FailureMessage />
</TestHistory>
</NewDataSet>

Can someone help me to show the results of datagirdview? temporarily I can only display it with richTextBox Below is the code I use:

private void Check(object sender, EventArgs e)
{
    check();
}
public void check()
{
    string CustomerName = cbWorkcell.Text;
    string SerialNumber = txtserialnumber.Text;
    string Division = "";
    try
    {
        ServiceMES.MES_TISSoapClient b = new ServiceMES.MES_TISSoapClient();        
        string resultz = b.GetTestHistory(SerialNumber, CustomerName, Division);           
        ShowResult(CustomerName, SerialNumber, resultz);               
    }

    catch { }
}

private void ShowResult(string CustomerName, string SerialNumber, string resultz)
{
  
    this.Invoke(new MethodInvoker(delegate ()
    {
       
        richTextBox1.Text = "Serinumber:" + SerialNumber + "\r\nCustomerName:" + CustomerName + "\r\n" + resultz + "\r\n";
        lbSerial.Text = "Serial: " + SerialNumber;
        
    }));
}
1 Answers

You can use DataSet.ReadXml and show the result in DataGridView.

For example:

var xml = @"
<NewDataSet>
<TestHistory>
    <StartTime>2021-01-09T17:37:38+07:00</StartTime>
    <StopTime>2021-01-09T17:37:42+07:00</StopTime>
    <TestStatus>P</TestStatus>
    <MachineName>HCMINGAOI06_B</MachineName>
    <Operator />
    <StepOrTestName>AOI_BSI</StepOrTestName>
    <FailureLabel />
    <FailureMessage />
</TestHistory>
</NewDataSet>
";
using (var textReader = new StringReader(xml))
{
    var ds = new DataSet();
    ds.ReadXml(textReader);
    dataGridView1.DataSource = ds.Tables[0];
}
Related