Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在datagridview中放置多个xml数据_C#_.net_Xml_Datagridview - Fatal编程技术网

C# 如何在datagridview中放置多个xml数据

C# 如何在datagridview中放置多个xml数据,c#,.net,xml,datagridview,C#,.net,Xml,Datagridview,假设我有多个xml数据,如下所示: <entry> <url><![CDATA[http://triada.kh.ua/made/?email=abuse@example.com]]></url> <phish_id>3779980</phish_id> <phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=3779980<

假设我有多个xml数据,如下所示:

<entry>
<url><![CDATA[http://triada.kh.ua/made/?email=abuse@example.com]]></url>
<phish_id>3779980</phish_id>
<phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=3779980</phish_detail_url>
<details>
<detail>
  <ip_address>93.190.41.34</ip_address>
  <cidr_block>93.190.40.0/21</cidr_block>
  <announcing_network>6849</announcing_network>
  <rir>ripencc</rir>
  <detail_time>2016-01-24T01:00:58+00:00</detail_time>
</detail>
</details>
<submission>
<submission_time>2016-01-22T22:42:56+00:00</submission_time>
</submission>
<verification>
<verified>yes</verified>
<verification_time>2016-03-28T14:15:01+00:00</verification_time>
</verification>
<status>
<online>yes</online>
</status>
<target>Internal Revenue Service</target>
</entry>

但是我的表被覆盖了,它只显示最后一个XmlData。请帮助。提前感谢

一个datagrid不能有多个数据源。如果有多个数据段,则需要将其合并在一起,然后将其绑定到网格。在您的示例中,可以使用Dataset.Merge方法

然而。。。我不确定您是如何获得数据的,但似乎不需要读取每个XML元素并从中创建数据集。您应该一次读取所有元素,然后将其绑定到网格

foreach (XElement result in query)

        {

            string display = result.ToString();

            XmlReader xmlFile;
            xmlFile = XmlReader.Create(new StringReader( display));
            DataSet ds = new DataSet();

            ds.ReadXml(xmlFile);

                dataGridView1.DataSource = ds.Tables[0];


        }