NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

RowsCollection.Add (Object[])

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

[Visual Basic]
Overloads Overridable Public Function Add( _
   ByVal values() As Object _
) As DataRow
[C#]
public virtual DataRow Add(
   object[] values
);
[C++]
public: virtual DataRow* Add(
   Object* values[]
);
[JScript]
public function Add(
   values : Object[]
) : DataRow;

Parameters

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

Return Value

The new DataRow.

Exceptions

Exception Type Condition
ArgumentException The array is larger than the number of columns in the table.
InvalidCastException A value doesn't match its respective column type.
ConstraintException Adding the row invalidates a constraint.
NoNullAllowedException Attempting to put a null in a column where AllowNull 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 throw an exception during either a ColumnChanging or RowChanging event. If an exception occurs, the row is not added to the table.

Example [Visual Basic]

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

[Visual Basic]

' The example presumes a DataTable with three columns. The first
' DataColumn object has its AutoIncrement property set to true
' necessitating that the first value of the array be set to 
' System.Object.Empty.
Private Sub AddRowByValues()
   Dim t As DataTable
   Dim rc As RowsCollection
   Dim myRow As DataRow
   Dim rowVals(2) As Object
   Set t = DataGrid1.DataGridTable.DataTable
   Set rc = t.Rows
   rowVals(0) = System.Object.Empty
   rowVals(1) = "hello"
   rowVals(2) = "world"
   Set myRow = rc.Add(rowVals) 
End Sub

See Also

RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Add Overload List | All | Clear | DataTable | DataRow | NewRow | Remove