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;
- values
- The array of values that are used to create the new row.
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.
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 );
}
Private Sub AddRow ( ByVal myTable As DataTable )
Dim myRows As DataRowCollection
Dim myNewRow As DataRow
' create an array with three elements.
Dim rowVals ( 2 ) As Object
myRows = myTable.Rows
rowVals ( 0 ) = "hello"
rowVals ( 1 ) = "world"
rowVals ( 2 ) = "two"
' add and return the new row.
myNewRow = myRows.Add ( rowVals )
End Sub |
|
C# |
VB |
DataRowCollection Members DataRowCollection.Add Overload List Clear DataTable DataRow NewRow Remove