C# save datatable as XML in SQL Server 2012/2014

Hi experts,

Did some research online and couldn't find a comprehensive solution to this so I'm coming to you guys for help. I have a simple datatable in C# and I'd like to insert/update into SQL server table as XML. Could you give me some code samples to get started on? Thanks!
timberadminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

Use DataSet to get the XML string.

private void SaveXMLToDatabase()
{

   DataSet dataSet = new DataSet("dataSet");
    DataTable table = dataSet.Tables.Add("Items");
    table.Columns.Add("id", typeof(int));
    table.Columns.Add("Item", typeof(string));

    // Add ten rows.
    DataRow row;
    for(int i = 0; i <10;i++)
    {
        row = table.NewRow();
        row["id"]= i;
        row["Item"]= "Item" + i;
        table.Rows.Add(row);
    }

     string xmlString = dataSet.GetXml();
// INSERT TO SQL DATABASE

}

Open in new window



https://msdn.microsoft.com/en-us/library/system.data.dataset.getxml(v=vs.110).aspx
0
timberadminAuthor Commented:
It's more of the inserting into SQL database code that I need...
0
plusone3055Commented:
take a look at this article it may help you more

Bulk Insertion of Data Using C# DataTable and SQL server OpenXML function

http://pranayamr.blogspot.com/2011/12/bulk-insertion-of-data-using-c.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.