save the information from an xml in sql

P

paulcc84

hi all. I need to save the mass information from an xml in
sql database from c # is not how. thanks
 
A

Arne Vajhøj

hi all. I need to save the mass information from an xml in
sql database from c # is not how. thanks

Do you want to parse the XML on the C# and insert
normal database types or do you want to have SQLServer
handle the XML?

Arne
 
A

Arne Vajhøj

want to parse the XML on the C# and insert
normal database type

Load the XML into a XmlDocument amd walk through it via
the good old GetElementsByTagName or the more modern
XPath SelectNodes assign the extracted values to
parameter values for SqlCommand INSERT statements.

(you could also use LINQ, but I doubt there will be
any benefits in this case)

If gave an example of XML then I may even provide a
small example of code.

Arne
 
A

Andy O'Neill

paulcc84 said:
want to parse the XML on the C# and insert
normal database type
I'm working with xml at the moment.
Here's a snippet, I've fiddled with it a bit to try and make it clearer what
it does.
I'm inserting into a datatable but you could stick whatever object there or
foreach a list or whatever.
My XML file is as flat as a file you'd ever find.


XDocument xd = XDocument.Load("file.xml");
var q = from c in xd.Descendants("xmlroot")
orderby (Int32)c.Element("ColID")
select c;
DataTable dt = ds.Tables[0];
foreach (var c in q)
{
DataRow row = dt.NewRow();
row["ColID"] = (Int32)c.Element("ColID");
row["FieldName"] = (String)c.Element("FieldName");
row["SeeInGrid"] = (Boolean)c.Element("SeeInGrid");
row["ColOrder"] = (Int32)c.Element("ColOrder");
row["DataType"] = (String)c.Element("DataType");

row["ColHeading"] = (String)c.Element("ColHeading");
row["ColWidth"] = (String)c.Element("ColWidth");
dt.Rows.Add(row);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Store XML/XSD in SQL Server 2008 3
Blob and XML 14
Creating and managing xml files 2
SQL query to XML 2
XML vs SQL Server 22
Binding XML Data to WPF 1
Linq to Xml 1
XML and SQL database 3

Top