title: Load XML file into SQL Server tables using C#
body: <p>I have complex XML file that export from old program in VB6, now I must write a program in C# to load this XML file into 2 tables. Here is the XML file structure:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="SHIFT-JIS" standalone="yes"?&gt;
  &lt;AdminFile&gt;
      &lt;PO_No&gt;&lt;/PO_No&gt;
      &lt;Database&gt;
          &lt;PO&gt;
              &lt;Table_PO_Master&gt;
                  &lt;DATA&gt;
                      &lt;PO_No&gt;&lt;/PO_No&gt;
                      &lt;PO_Date&gt;&lt;/PO_Date&gt;
                  &lt;/DATA&gt;             
              &lt;/Table_PO_Master&gt;
              &lt;Table_PO_Details&gt;
                  &lt;DATA&gt;
                      &lt;PO_No&gt;&lt;/PO_No&gt;
                      &lt;GOODS_CD&gt;&lt;/GOODS_CD&gt;
                      &lt;QTY&gt;&lt;/QTY&gt;
                  &lt;/DATA&gt;             
              &lt;/Table_PO_Details&gt;
          &lt;/PO&gt;
      &lt;/Database&gt;
  &lt;/AdminFile&gt;
  </code></pre>
  
  <p>I need to load this XML into 2 SQL Server tables that have the structure as below:</p>
  
  <p>Table_PO_Master(Id,PO_No,PO_Date)</p>
  
  <p>Table_PO_Details(PO_No,GOODS_CD,QTY)</p>
  
  <p>I googled and found this code but do not know to to apply it in my case.</p>
  
  <pre><code>string myXMLfile = "D:\\MyXML.xml";
  XmlTextReader textReader = new XmlTextReader(myXMLfile);
                  XmlDocument doc = new XmlDocument();
                  doc.Load(myXMLfile);
                  XmlNodeList List = doc.GetElementsByTagName("RWResponse");
  
                  foreach (XmlNode node in List)
                  {
                      XmlNode Element = (XmlNode)node;
                      foreach (XmlNode node1 in Element)
                      {
                          XmlNode Element1 = (XmlNode)node1;
                          foreach (XmlNode node2 in Element1)
                          {
                              XmlNode Element2 = (XmlNode)node2;
                              foreach (XmlNode node3 in Element2)
                              {
                                  XmlNode Element3 = (XmlNode)node3;
                                  if (Element3.Name.ToUpper() != "HEADER")
                                  {
                                      if (!Element3.OuterXml.ToString().Contains("ROW type=\"subtotal\""))
                                      {
                                          if (!Element3.OuterXml.ToString().Contains("ROW type=\"total\""))
                                          {
                                              DataRow dr = ret_XML_Data_in_DataTable.NewRow();                                           
                                              foreach (XmlNode node4 in Element3)
                                              {
                                                  XmlElement Element4 = (XmlElement)node4;
  
                                              }
                                           }
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
  </code></pre>