DekGenius.com
[ Team LiB ] Previous Section Next Section

9.1 Creating a DataRow

A DataRow is created by calling the NewRow( ) method of a DataTable, a method that takes no arguments. The DataTable supplies the schema, and the new DataRow is created with default or empty values for the fields:

// create a table with one column
DataTable dt = new DataTable();
dt.Columns.Add("MyColumn",  typeof(System.String));

// create a row with the same schema as DataTable dt
DataRow row = dt.NewRow();
row["MyColumn"] = "Item 1";

// add the row to the table
dt.Rows.Add(row);
    [ Team LiB ] Previous Section Next Section