1

Using LINQ , I have successfully parsed an XML into an object array lv1s as below.

var lv1s = from lv1 in xdoc.Descendants("build")
           select new
           {
               Number = lv1.Descendants("number"),
               Result = lv1.Descendants("result"),
               Timestamp = lv1.Descendants("timestamp")
           };

Wanted to know what is the simplest way to convert this object array into a datatable with columns Number,Result,timestamp?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
mhn
  • 2,660
  • 5
  • 31
  • 51
  • 1
    Create a new datatable with those columns, then loop through entries in `lv1s` and add rows for each? – Daniel Kelley Jun 16 '14 at 11:42
  • *Why* do you want it in a `DataTable`? Is there a specific reason for that? (`DataTable` is vastly overused) – Marc Gravell Jun 16 '14 at 11:44
  • I am trying to use SqlBulkCopy . It requires a datatable as parameter. So wanted to check if there is a work around, instead of looping through each item. – mhn Jun 16 '14 at 11:56
  • @mhn Try `dataSet.ReadXml` http://msdn.microsoft.com/en-us/library/fx29c3yd(v=vs.90).aspx – Suraj Singh Jun 16 '14 at 12:41
  • @SurajSingh . Thanks .. This looks like the simplest method available for my issue. Please make it an answer. Will choose as best answer. – mhn Jun 17 '14 at 07:23
  • @mhn Well since your question is marked as duplicate no-one can post any answer on this question.However i'm glad if that link helped. – Suraj Singh Jun 18 '14 at 14:29

0 Answers0