Export (0) Print
Expand All

RowNotInTableException Class

Represents the exception that is thrown when trying to perform an operation on a DataRow that is not in a DataTable.

For a list of all members of this type, see RowNotInTableException Members.

System.Object
   System.Exception
      System.SystemException
         System.Data.DataException
            System.Data.RowNotInTableException

[Visual Basic]
<Serializable>
Public Class RowNotInTableException
   Inherits DataException
[C#]
[Serializable]
public class RowNotInTableException : DataException
[C++]
[Serializable]
public __gc class RowNotInTableException : public DataException
[JScript]
public
   Serializable
class RowNotInTableException extends DataException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

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.

Example

[Visual Basic, C#, C++] The following example creates a DataTable with one DataColumn and 10 DataRow objects. After deleting a row, the AcceptChanges method is called causing the RowNotInTableException to be thrown.

[Visual Basic] 
Private Sub DemonstrateRowNotInTableException()
    ' 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
        Console.WriteLine("Row not in table")
    End Try
End Sub 'DemonstrateRowNotInTableException

[C#] 
private void DemonstrateRowNotInTableException(){
    // 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){
       Console.WriteLine("Row not in table");
    }
 }

[C++] 
private:
void DemonstrateRowNotInTableException(){
    // Create a DataTable with one column and ten rows.      
    DataTable* myTable = new DataTable(S"myTable");
    DataColumn* myColumn = new DataColumn(S"col1");
    myTable->Columns->Add(myColumn);
    DataRow* newRow;
    for(int i = 0;i <10;i++){
    newRow = myTable->NewRow();
    newRow->Item[S"col1"] = __box(i);
    myTable->Rows->Add(newRow);
    }
    try{
       // Remove a row and invoke AcceptChanges.
       DataRow* removedRow = myTable->Rows->Item[9];
       removedRow->Delete();
       removedRow->AcceptChanges();
 
    }
    catch(System::Data::RowNotInTableException* /*rowException*/){
       Console::WriteLine(S"Row not in table");
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Data

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Data (in System.Data.dll)

See Also

RowNotInTableException Members | System.Data Namespace

Show:
© 2014 Microsoft