Reputation: 883
In my project I need to read a csv file and convert it into xml and save the xml to database table. I want to save the xml Output directly to database without saving to a file. I was able to convert csv to xml, but I am not sure how to save it(without saving to a file) database directly. Any help is appreciated.
Here is my code
var lines = System.IO.File.ReadAllLines(@"C:\test.csv");
var xml = new XElement("TopElement",
lines.Select(line => new XElement("Item",
line.Split(';')
.Select((column, index) => new XElement("Column" + index, column)))));
// XmlTextReader reader = new XmlTextReader(xml.ToString());
//xml.Save(@"C:\xmloutput.xml); // dont want to save to file.
Upvotes: 0
Views: 5605
Reputation: 335
Implementing XML in SQL Server:
http://msdn.microsoft.com/en-us/library/ms189887(SQL.105).aspx
Other links:
http://forums.asp.net/t/1316853.aspx/1
Upvotes: 0
Reputation: 335
Maintaining XML in SQL Server:
http://msdn.microsoft.com/en-us/library/bb510480(SQL.105).aspx
C# sample (converting XML to string): http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/d1666d13-dea3-4ce8-a818-6b852a63de4f/
Upvotes: 0
Reputation: 9942
Do you have column of type "XMl" in database in case you are using SQL Server?
You can check Save XML directly to Database with C#
Upvotes: 2