.NETGURU
Writing to SQL from XmlDataDocument problem
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngxml' list.


Bob Herrmann
I am new to working with XML files so I am hoping someone can help me out. I have a xml file and schema that a customer sent me. I want to take this xml table and load it into my SQL Server 2000 database in a table which already exists. I have managed to load the xml table into a XmlDataDocument. Now I want to read thru the XmlDataDocument and INSERT or UPDATE into my SQL table. I am using ASP.Net and VB.Net. I am sure there is an easy way to read thru the XmlDataDocument and perform my inserts and updates but I cannot seem to find any examples.

Thanks,
Bob
Reply to this message...
 
    
Tim Curtin
It's a start:
Public Function UpdateCustomerXMLXFile() As boolean
dim nl as System.Xml.XmlNodeList
    dim ds as New DataSet
dim oXML as New System.Xml.XmlDataDocument
dim node as System.Xml.XmlElement
dim oXNode as Object
nl = oxml.SelectNodes("//Customer")
with oXML
.Load( Server.MapPath("customers.xml"))
dim oConn as New SqlConnection("data source=(local)user
id=user;password=password;initial catalog=northwind")
oconn.Open
dim row as DataRow
nl=oxml.SelectNodes("//customer")
dim da as New SqlDataAdapter( "select * from table where key
=0",oconn)'return empty ds
da.Fill(ds,"customers")
for each node in nl
row(0)=node.selectSingleNode("firstname")
row(1)=node.selectsinglenode("lastname")
ds.Tables(0).Rows.Add( row )
next
da.Update (ds)
oconn.Close
oconn=nothing
End With
UpdateCustomerXMLFile=true
End Function

[Original message clipped]

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Reply to this message...
 
    
Bob Herrmann
Thanks for the code example Tim. I am having some problems with it though.
I don't understand the line:

nl = oxml.SelectNodes("//Customer")

Can someone explain what this does?

thanks
Bob
----- Original Message -----
From: "Tim Curtin" <Click here to reveal e-mail address>
To: "aspngxml" <Click here to reveal e-mail address>
Sent: Tuesday, July 16, 2002 1:08 PM
Subject: [aspngxml] Re: Writing to SQL from XmlDataDocument problem

[Original message clipped]

Reply to this message...
 
    
Tim Curtin
it returns a node collection representing each customer element(node).

[Original message clipped]

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

Reply to this message...
 
    
Bob Herrmann
I have a xml file named bobxmldoc.xml and I want to write rows to a SQL
table named tabCatalog. Can you show me the lines in your example code that
would be changed to accomplish this? I am new to XML and I have not got the
terminology down yet.

Thanks,
Bob
----- Original Message -----
From: "Tim Curtin" <Click here to reveal e-mail address>
To: "aspngxml" <Click here to reveal e-mail address>
Sent: Wednesday, July 17, 2002 4:35 PM
Subject: [aspngxml] Re: Writing to SQL from XmlDataDocument problem

[Original message clipped]

Reply to this message...
 
 
System.Data.DataRow
System.Data.DataSet
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Xml.XmlDataDocument
System.Xml.XmlElement
System.Xml.XmlNodeList




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification