Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do insert xml file into sql with trans-act?

Author  Topic 

Cwm
Starting Member

39 Posts

Posted - 2009-01-26 : 17:59:01
Hi everyone,
I was wondering how to correctly insert data from an xml file into a sql table?
The xml file i created using c# and pulled it out of a database at work, I have the identical database at home without the data ( I did a back up of it and couldn't figure out how to copy the data )So i need to populate my table with the xml file.

Thanks

Chris

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-01-27 : 10:38:34
If you "did a backup of it" then the backup contains the data as well. Perhaps you simply SCRIPTED out the database and table structure rather than performing a sql backup? Easiest way is go back to work and do a BACKUP DATABASE then RESTORE that backup on your home server.

To answer your question, there are more than a few ways to get xml data into existing sql server objects. Here's one:
http://weblogs.sqlteam.com/mladenp/archive/2007/06/18/60235.aspx

Be One with the Optimizer
TG
Go to Top of Page

Cwm
Starting Member

39 Posts

Posted - 2009-01-27 : 18:15:14
Hi TG,
Thanks for the help...You are right i scripted the database, and did not do a full backup.
Thanks for the direction on the xml to sql...What sucks is when i created the xml file, the datetime columns from the sql tables look ike this...
2009-01-07T14:44:00-05:00
I am guessing that this is time zoned which i do not want, i wanted it to come out as this... 01/07/2009 4:44 PM. So i do not know what went wrong there. I can't even get it into the table now because of the datetime format..What I do to import the xml file into sql is ( in c# ) populate a dataset with it then use sqlbulkcopy...But yea the xml file gives me a problem now because of the datetime format that it did.

Chris
Go to Top of Page
   

- Advertisement -