2015-11-03 71 views
0

我不會在行中添加行,我有我的軟件的xml數據庫,但我不明白如何爲此樣式添加行。vb.net add row in row xml

<facture> 
    <commande>000156</commande> 
    <date>Jan 1, 2003 14:30:00</date> 
    <commis>adsd</commis> 
    <client>0</client> 
    <item_liste> 
     <item_id>0</item_id> 
     <item_quantité>4</item_quantité> 
     <item_codebarre>0</item_codebarre> 
     <item_name>hejwkhe</item_name> 
     <item_price>55</item_price>     
     <item_tax>no</item_tax> 
    </item_liste> 
    <item_liste> 
     <item_id>2</item_id> 
     <item_quantité>5</item_quantité> 
     <item_codebarre>0</item_codebarre> 
     <item_name>ghskjfdghsfd</item_name> 
     <item_price>24</item_price>     
     <item_tax>yes</item_tax> 
    </item_liste> 
    <montant> 270 </montant> 
</facture> 

我現在添加的標準行

dataTable1.Rows.Add(img12, "", "", "", "", "", "") 

感謝您的幫助,我對我的英語不好對不起。

+0

顯示結果你所期望 – Fabio

+0

什麼結果是什麼,我露面,但如果我在我的帳上有5個項目我有5 ,並且豈不等於只行我有和我的XML基礎是<?XML版本= 「1.0」 編碼= 「UTF-8」?>

回答

0

您可以使用XML的LINQ

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string xml = 
       "<facture>" + 
        "<commande>000156</commande>" + 
        "<date>Jan 1, 2003 14:30:00</date>" + 
        "<commis>adsd</commis>" + 
        "<client>0</client>" + 
        "<item_liste>" + 
         "<item_id>0</item_id>" + 
         "<item_quantité>4</item_quantité>" + 
         "<item_codebarre>0</item_codebarre>" + 
         "<item_name>hejwkhe</item_name>" + 
         "<item_price>55</item_price>" + 
         "<item_tax>no</item_tax>" + 
         "</item_liste>" + 
        "<item_liste>" + 
         "<item_id>2</item_id>" + 
         "<item_quantité>5</item_quantité>" + 
         "<item_codebarre>0</item_codebarre>" + 
         "<item_name>ghskjfdghsfd</item_name>" + 
         "<item_price>24</item_price>" + 
         "<item_tax>yes</item_tax>" + 
         "</item_liste>" + 
         "<montant> 270 </montant>" + 
        "</facture>"; 


      XElement facture = XElement.Parse(xml); 
      List<XElement> item_liste = facture.Descendants("item_liste").ToList(); 
      XElement newItem_liste = new XElement("item_liste", new XElement[] { 
       new XElement("item_id", 3), 
       new XElement("item_quantité", 5), 
       new XElement("item_codebarre", 0), 
       new XElement("item_name", "xyz"), 
       new XElement("item_price", 30), 
       new XElement("item_tax", "no") 
      }); 
      item_liste.Last().ReplaceWith(new object[] { item_liste.Last(), newItem_liste }); 
     } 
    } 
} 
​ 
0
Dim dr As DataRow 

' loop around the XML Nodes 
    For Each node As XmlNode In XML 

    ' declare a new row in your datatable 
dr = dataTable1.NewRow() 
'get what ever values you want off of the attribute of the node ie item name 
dr("item_name") = node.Attributes("item_name").Value 
dr("item_id") = node.Attributes("item_id").Value 

' add the row to your data table 
datatable1.rows.Add(dr) 
+0

嗨,我不undertand,怎麼增加新的價值我f我添加相同的值?謝謝。 –