parse xml file insert into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jgn1013
    New Member
    • Jan 2007
    • 5

    parse xml file insert into database

    This is what i'm currently doing, but what I would like is parse the xml only get phone, cellphone, name & userid.

    I'm getting a http stream xml file: sample below
    Code:
    <root>
    <bhcontact name="john doe" userid="123">
      <address>my address here</address>
     <phone>123-456-7890</phone>
      <cellphone>123-456-7888</cellphone>
       <state>GA</state>
       <zip>12345</zip>
    </bhcontact>
    </root>
    
    
    DataSet xmlDS = new DataSet();
    DataRow dataRow;
    DataSet dbDS = new DataSet("contactxml");
    xmlDS.ReadXml(new StringReader("XML STRING HERE--see above"));
    trcCon.Open();
    			SqlDataAdapter trcDA = new SqlDataAdapter("Select * from clientcontact where 1=2", trcCon);
    			trcDA.Fill(dbDS, "contactxml");
    			foreach(DataRow drow in xmlDS.Tables[0].Rows)
    			{
    				dataRow = dbDS.Tables[0].NewRow();
    				for(int i=1; i <xmlDS.Tables[0].Columns.Count; i++)
    {
     dataRow[i] = drow[i];
    }
    dbDS.Tables[0].Rows.Add(dataRow);
    				SqlCommandBuilder trcCmd = new SqlCommandBuilder(trcDA);
    				trcDA.Update(dbDS, "contactxml");
    				
    				trcCon.Close();
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    One way may be to alter your select statement. HTH.

    Comment

    Working...