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


Get ADO.NET in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.