System.Data Namespace
Represents the exception that is thrown when trying to perform an operation on a DataRow that is not in a DataTable.
The RowNotInTableException is thrown when invoking the following methods on a row that has been deleted with either the Delete or the DataRowCollection.Remove method.
The following example initializes a DataTable with one DataColumn and 10 DataRow objects. After deleting a row, the AcceptChanges method is called causing the RowNotInTableException to be thrown.
private void RowNotInTableExceptionDemo ( ) {
// create a DataTable with one column and ten rows.
DataTable myTable = new DataTable ( "myTable" );
DataColumn myColumn = new DataColumn ( "col1" );
myTable.Columns.Add ( myColumn );
DataRow newRow;
for ( int i = 0;i <10; i++ ) {
newRow = myTable.NewRow ( );
newRow [ "col1" ] = i;
myTable.Rows.Add ( newRow );
}
try {
// remove a row and invoke AcceptChanges.
DataRow removedRow = myTable.Rows [ 9 ];
removedRow.Delete ( );
removedRow.AcceptChanges ( );
}
catch ( System.Data.RowNotInTableException rowException ) {
Response.Write ( "RowNotInTableException" );
Response.Write ( rowException.Message );
}
}
Private Sub RowNotInTableExceptionDemo ( )
' create a DataTable with one column and ten rows.
Dim myTable As New DataTable ( "myTable" )
Dim myColumn As New DataColumn ( "col1" )
myTable.Columns.Add ( myColumn )
Dim newRow As DataRow
Dim i As Integer
For i = 0 To 9
newRow = myTable.NewRow ( )
newRow ( "col1" ) = i
myTable.Rows.Add ( newRow )
Next i
Try
' Remove a row and invoke AcceptChanges.
Dim removedRow As DataRow = myTable.Rows ( 9 )
removedRow.Delete ( )
removedRow.AcceptChanges ( )
Catch rowException As System.Data.RowNotInTableException
Response.Write ( "RowNotInTableException" )
Response.Write ( rowException.Message )
End Try
End Sub |
|
C# |
VB |