3

I know how to do simple Linq To XML. Export a sql server database table data. A simple query like follow will work:

xmlDoc = new XElement("TestPoints",
                from test in myDB.TestPoints
                select
                new XElement("TestPoint",
                    new XElement("Id", test.Id),
                    new XElement("Value", test.Value),
                    new XElement("Time", test.Time),
                    new XElement("TestId", test.TestId)
                    )
                );
            xmlDoc.Save("test.xml");

However, in this case, i need to specify every database column those I need to export. What I need is to export a table which have more than 30 columns. Now, its a bit painful to make such repetitively task of creating new XElement. Is there any way to dump the full table and all its columns/rows to a xml file in LinQ easily please? Without specify each column externally. Thanks.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Rana
  • 5,912
  • 12
  • 58
  • 91
  • You can select the xml from db and the xml can be selected via LINQ. http://msdn.microsoft.com/en-us/library/ms345137%28v=sql.90%29.aspx – TcKs Jun 23 '11 at 12:21

1 Answers1

4

Put Data of sql server table in DataTable

and than use DataTable.WriteXml will do your task easily.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263