Wednesday, September 7, 2011

an example of creating a DataTable from nothing

[TestMethod]

public void SortingOfDataTableTest()

{

   DataTable dataTable = new DataTable();

   dataTable.Columns.Add("Foo", typeof(string));

   dataTable.Columns.Add("Bar", typeof(Int32));

   dataTable.Columns.Add("Baz", typeof(string));

   dataTable.Rows.Add();

   dataTable.Rows[0][0] = "Qux";

   dataTable.Rows[0][1] = 6;

   dataTable.Rows[0][2] = "Whatever";

   Assert.AreEqual(dataTable.Rows.Count, 1);

   Assert.AreEqual(dataTable.Columns.Count, 3);

   Assert.AreEqual(dataTable.Rows[0][1], 6);

}

No comments:

Post a Comment