System.Data Namespace DataRowCollection Class
Removes the row at the given index.
[ VB ]
Public Sub RemoveAt ( _
ByVal index As Integer _
)
[ C# ]
public void RemoveAt (
int index
);
[ C++ ]
public: void RemoveAt (
int index
);
[ JScript ]
public function RemoveAt (
index : int
);
- index
- The index of the row to remove.
Exception Type |
Condition |
ArgumentException |
The collection does not have a row at the specified index. |
Use the RemoveAt method to remove the DataRow object at the specified index in the DataRowCollection.
To remove a specified DataRow object, use the Remove method. You can also use the Clear method to remove all members of the collection at once.
When a row is removed, data in that row is lost. You can also call the DataRow class's Delete method to simply mark a row for removal. The row is not actually removed until the AcceptChanges method is invoked.
The following example removes the last row in a DataRowCollection by calling the RemoveAt method.
private void RemoveRowByIndex ( DataTable myTable ) {
DataRowCollection myRows = myTable.Rows;
if ( myRows.Count == 0 ) return;
myRows.RemoveAt ( myRows.Count - 1 );
}
Private Sub RemoveRowByIndex ( myTable As DataTable )
Dim myRows As DataRowCollection = myTable.Rows
If myRows.Count = 0 Then Exit Sub
myRows.RemoveAt ( myRows.Count - 1 )
End Sub |
|
C# |
VB |
DataRowCollection Members Clear Add