System.Data Namespace
Represents the exception that is thrown when an action is attempted on a DataRow that has been deleted.
To delete a DataRow, use the DataRow class' s Delete method. Once you have deleted a row, any attempts to manipulate it will generate the DeletedRowInaccessibleException.
The DeletedRowInaccessibleException is thrown when using one of the following properties or methods that attempt to get or set the value of a deleted DataRow:
Use the DataRow class' s RowState to determine if a row has been deleted.
The following example deletes a DataRow from a DataTable. A subsequent attempt to read a value from the deleted row causes the DeletedRowInaccessibleException to be thrown.
private void DeletedRowInaccessibleExceptionExceptionDemo ( ) {
// create a DataTable with one column.
DataTable myTable = new DataTable ( "myTable" );
DataColumn myColumn = new DataColumn ( "col1" );
myTable.Columns.Add ( myColumn );
// add ten rows to the table.
DataRow newRow;
for ( int i = 0;i <10; i++ ) {
newRow = myTable.NewRow ( );
newRow [ "col1" ] = i;
myTable.Rows.Add ( newRow );
}
myTable.AcceptChanges ( );
try {
// delete a row and try to read it.
myTable.Rows [ 9 ].Delete ( );
Response.Write ( myTable.Rows [ 9 ] [ "col1" ] );
}
catch ( DeletedRowInaccessibleException rowException ) {
Response.Write ( "DeletedRowInaccessibleException" );
Response.Write ( rowException.Message );
}
}
Private Sub DeletedRowInaccessibleExceptionExceptionDemo ( )
' create a DataTable with one column.
Dim myTable As DataTable = New DataTable ( "myTable" )
Dim myColumn As DataColumn = New DataColumn ( "col1" )
myTable.Columns.Add ( myColumn )
' add ten rows to the table.
Dim i As Integer
Dim myRow As DataRow
For i = 0 To 9
myRow = myTable.NewRow ( )
myRow ( 0 ) = i
myTable.Rows.Add ( myRow )
Next
myTable.AcceptChanges ( )
Try
' delete a row and try to read it
myTable.rows ( 9 ).Delete ( )
Response.Write ( myTable.Rows ( 9 ) ( "col1" ) )
Catch rowException As DeletedRowInaccessibleException
Response.Write ( "DeletedRowInaccessibleException" )
Response.Write ( rowException.Message )
End Try
End Sub |
|
C# |
VB |
BeginEdit DataRow DataRowState Delete Item ItemArray RowState