System.Data Namespace DataRowCollection Class
Adds a row to the DataTable.Rows collection.
1. Adds the specified DataRow object to the collection.
2. Initializes a row using specified values and adds it to the collection.
The following example uses the Add method to create and add a new DataRow object to a DataRowCollection.
NOTE: This example uses one of the overloaded versions of Add. For other examples that may be available, see the individual overload topics.
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