asp.net.ph

DataRowCollection.Add Method ( Object [ ] )

System.Data Namespace   DataRowCollection Class


Creates a row using specified values and adds it to the DataRowCollection.

[ VB ]
Overridable Overloads Public Function Add ( _
   ByVal values ( ) As Object _
) As DataRow

[ C# ]
public virtual DataRow Add (
   object [ ] values
 );

[ C++ ]
public: virtual DataRow* Add (
   Object* values __gc [ ]
);

[ JScript ]
public function Add (
   values : Object [ ]
) : DataRow;

Parameters

values
The array of values that are used to create the new row.

Exceptions


Exception Type Condition
ArgumentException Occurs when the array is larger than the number of columns in the table.
InvalidCastException Occurs when a value does not match its respective column type.
ConstraintException Occurs when Adding the row invalidates a constraint.
NoNullAllowedException Occurs when Attempting to put a null in a column where AllowDBNull is false.

Remarks

If a DataColumn object has its AutoIncrement set to True, System.Object.Empty should be passed to get the default value for that column.

Exceptions can also occur if you generate an exception during either a ColumnChanging or RowChanging event. If an exception occurs, the row is not added to the table.

Example

The following example uses the Add method to create and add a new DataRow object to a DataRowCollection.

private void AddRow ( DataTable myTable ) {
   DataRowCollection myRows;
   DataRow myNewRow;
   // create an array with three elements.
   object [ ] rowVals = new object [ 3 ];
   myRows = myTable.Rows;
   rowVals [ 0 ] = "hello";
   rowVals [ 1 ] = "world";
   rowVals [ 2 ] = "two";
   // add and return the new row.
   myNewRow = myRows.Add ( rowVals );
}
  C# VB

See Also

DataRowCollection Members   DataRowCollection.Add Overload List   Clear   DataTable   DataRow   NewRow   Remove 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