Adds the specified DataRow to the RowsCollection object.
[Visual Basic] Overloads Public Sub Add( _ ByVal row As DataRow _ ) [C#] public void Add( DataRow row ); [C++] public: void Add( DataRow* row ); [JScript] public function Add( row : DataRow );
Exception Type | Condition |
---|---|
ArgumentNullException | The row is null. |
ArgumentException | The row either belongs to another table or already belongs to this table. |
ConstraintException | The addition invalidates a constraint. |
NoNullAllowedException | The addition tries to put a null in a DataColumn where AllowNull is false |
To create a new DataRow, you must use the DataTable class's NewRow method. When you use the NewRow method, a new DataRow object is returned using the schema of parent DataTable. After you create the DataRow object and set the values for each of its columns, use the Add method to add the object to the collection.
Throws an exception if the user throws an exception in the RowChanging event. If an exception occurs, the row is not added to the table.
The following example uses the Add method to add a new DataRow to a RowsCollection object.
[Visual Basic]
Private Sub AddDataRow() Dim t As DataTable Dim rc As RowsCollection Dim r As DataRow Set t = DataGrid1.DataGridTable.DataTable Set rc = t.Rows Set r = t.NewRow r(0) = "hello" r(1) = "world" rc.Add(r) End Sub
RowsCollection Class | RowsCollection Members | System.Data Namespace | RowsCollection.Add Overload List | All | Clear | DataTable | DataRow | NewRow | Remove