25.3 Collections Reference

ItemArray

 Object[]   itemArray   = DataRow.ItemArray; 

Gets or sets the values for the columns in the row as an object array.

Example

The following example demonstrates how to use the ItemArray collection property to set values for the columns in a row:

 // create a table with two columns DataTable dt = new DataTable(); DataColumn colId = new DataColumn("ProductId", typeof(System.Int32)); DataColumn colDesc = new DataColumn("Description", typeof(System.String)); dt.Columns.AddRange(new DataColumn[] {colId, colDesc}); // add a row using ItemArray object[] rowArray = new object[] {1, "Widget"}; DataRow row = dt.NewRow(); row.ItemArray = rowArray; dt.Rows.Add(row); // get the data for the row using the ItemArray property object[] row = dt.Rows[0].ItemArray; 

Note

When the ItemArray property is used, an attempt is made to locate the row matching the primary key. If the row is found, it is updated with the values in the ItemArray ; otherwise , a new row is created. Any columns with an array element set to null are set to the default value for the column. The value for AutoIncrement columns should also be set to null in the ItemArray .



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