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); 

ADO. NET in a Nutshell
ADO.NET in a Nutshell
ISBN: 0596003617
EAN: 2147483647
Year: 2005
Pages: 415

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net