title: Serialize DataTable (Dataset) to Object
body: <p>I have one class and one query from the database, filling DataTable in the DataSet. I would like to populate the object with the data from the DataTable &amp; DataSet. How can I do so?</p>
  
  <p>Object: </p>
  
  <pre><code> public class Marks
      {
          public List&lt;Mark&gt; MarkList { get; set; }
  
          public Marks()
          {
              MarkList = new List&lt;Mark&gt;();
          }
      }
  
  
      public class Mark
      { 
          public String Number { get; set; }
  
          public String Word { get; set; }
  
          public DateTime? DateIn { get; set; }
  
          public DateTime? DateOut { get; set; }
      }
  </code></pre>
  
  <p>I tried to do so:</p>
  
  <pre><code>private void BindMarksSerialize()
  {      
      FillDataTable(dtMarks, MarksCMD);
  
      MemoryStream stream = new MemoryStream();
      dtMarks.WriteXml(stream);
      XmlSerializer serializer = new XmlSerializer(typeof(Marks), new XmlRootAttribute("Marks")); 
      File.WriteAllBytes("C:\\Out.xml", stream.ToArray());
  
  
      StreamReader reader = new StreamReader("C:\\Out.xml");
      var marks = (Marks)serializer.Deserialize(reader);
      reader.Close();
  }
  
  private void FillDataTable(DataTable dataTable, Object sqlCommandContainer)
  {
      var sqlCommand = sqlCommandContainer as SqlCommand;
      var sqlDataAdapter = sqlCommandContainer as SqlDataAdapter;
      if (sqlDataAdapter == null &amp;&amp; sqlCommand == null)
          return;
  
          dataTable.Clear();
          if (sqlCommand != null)
          {
              sqlCommand.Connection.Open();
              dataTable.Load(sqlCommand.ExecuteReader());
          }
          else
              sqlDataAdapter.Fill(dataTable);
   }
  </code></pre>
  
  <p>The result is needed to populate XML:</p>
  
  <pre><code>&lt;Marks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;MarkList&gt;
      &lt;Mark&gt;
        &lt;Number&gt;1&lt;/Number&gt;
        &lt;Word&gt;123123123&lt;/Word&gt;
        &lt;DateIn xsi:nil="true" /&gt;
        &lt;DateOut xsi:nil="true" /&gt;      
      &lt;/Mark&gt;
    &lt;/MarkList&gt;
  &lt;/Marks&gt;
  </code></pre>
  
  <p>I got:</p>
  
  <pre><code>&lt;NewDataSet&gt;
    &lt;Mark&gt;
      &lt;Number&gt;110938&lt;/Number&gt;
      &lt;Word&gt;110938&lt;/Word&gt;
      &lt;DateIn&gt;1993-04-08T00:00:00+05:00&lt;/DateIn&gt;
      &lt;DateOut&gt;2002-02-04T00:00:00+04:00&lt;/DateOut&gt;    
    &lt;/Mark&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>Prompt can anyone knows how to do this?</p>