Thursday, October 21, 2010

Create datatable at runtime c#


//declares datatable
DataTable dt= new DataTable("parameter_final_result");
dt.Clear();
  
//delcares and add new datacolumn
DataColumn col1 = new DataColumn("parameter", Type.GetType("System.String"));
DataColumn col2= new DataColumn("rating", Type.GetType("System.String"));
DataColumn col3 = new DataColumn("material", Type.GetType("System.String"));
DataColumn col4 = new DataColumn("failed_result", Type.GetType("System.String"));
DataColumn col5 = new DataColumn("unit", Type.GetType("System.String"));
DataColumn col6 = new DataColumn("date_prepared", Type.GetType("System.DateTime"));
  
//add datacolumn to datatable
dt.Columns.Add(col1);
dt.Columns.Add(col2);
dt.Columns.Add(col3);
dt.Columns.Add(col4);
dt.Columns.Add(col5);
dt.Columns.Add(col6);

No comments:

Post a Comment