asp.net.ph

DataRow.ItemArray Property

System.Data Namespace   DataRow Class


Sets or retrieves all of the values for this row through an array.

[ VB ]
Public Property ItemArray As Object ( )

[ C# ]
public object [ ] ItemArray {get; set;}

[ C++ ]
public: __property Object* get_ItemArray ( );
public: __property void set_ItemArray ( Object* [ ] );

[ JScript ]
public function get ItemArray ( ) : Object [ ];
public function set ItemArray ( Object [ ] );

Property Value

An array of type Object.

Exceptions


Exception Type Condition
ArgumentException Occurs when the array is larger than the number of columns in the table.
InvalidCastException Occurs when a value in the array does not match its DataType in its respective DataColumn.
ConstraintException Occurs when an edit broke a constraint.
ReadOnlyException Occurs when an edit tried to change the value of a read-only column.
NoNullAllowedException Occurs when an edit tried to put a null value in a column where the DataColumn object's AllowNull is false.
DeletedRowInaccessibleException Occurs when the row has been deleted.

Remarks

If a DataColumn has its DefaultValue property set, pass a null reference in the array to set the default value for that column. Similarly, if a column has its AutoIncrement property set to true, pass a null reference ( Nothing ) in the array to set the automatically generated value for the row.

An exception can occur if a user throws an exception in the ColumnChanging event, or the RowChanging event.

Example

The following examples show how to get and set values using the ItemArray property.

private void CreateRowsWithItemArray ( ) {
   // make a DataTable using the function below.
   DataTable dt = MakeTableWithAutoIncrement ( );
   DataRow dr;
   // declare the array variable.
   object [ ] myArray = new object [ 2 ];
   // create 10 new rows and add to DataRowCollection.
   for ( int i = 0; i <10; i++ ) {
      myArray [ 0 ] = null;
      myArray [ 1 ] = "item " + i;
      dr = dt.NewRow ( );
      dr.ItemArray = myArray;
      dt.Rows.Add ( dr );
  }
   PrintTable ( dt );
}

private DataTable MakeTableWithAutoIncrement ( ) {
   // make a table with one AutoIncrement column.
   DataTable myTable = new DataTable ( "myTable" );
   DataColumn dcID = new DataColumn ( "id", Type.GetType ( "System.Int32" ) );
   dcID.AutoIncrement = true;
   dcID.AutoIncrementSeed = 10;
   myTable.Columns.Add ( dcID );

   DataColumn dcFirstName = new DataColumn ( "Item", Type.GetType ( "System.String" ) );
   myTable.Columns.Add ( dcFirstName );
   return myTable;
}

private void PrintTable ( DataTable myTable ) {
   foreach ( DataRow myRow in myTable.Rows ) {
      foreach ( DataColumn myColumn in myTable.Columns ) {
         Response.Write ( myRow [ myColumn ] );
     }
   }
}
  C# VB

See Also

DataRow Members   AcceptChanges   AutoIncrement   DataColumn Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph