Share via


RowNotInTableException 类

表示尝试在不位于 DataTable 中的 DataRow 上执行操作时引发的异常。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
<SerializableAttribute> _
Public Class RowNotInTableException
    Inherits DataException
用法
Dim instance As RowNotInTableException
[SerializableAttribute] 
public class RowNotInTableException : DataException
[SerializableAttribute] 
public ref class RowNotInTableException : public DataException
/** @attribute SerializableAttribute() */ 
public class RowNotInTableException extends DataException
SerializableAttribute 
public class RowNotInTableException extends DataException

备注

在已经用 DeleteDataRowCollection.Remove 方法删除的行上调用以下方法时,引发 RowNotInTableException

示例

下面的示例创建一个具有 1 个 DataColumn 对象和 10 个 DataRow 对象的 DataTable。删除一行后,将调用 AcceptChanges 方法,进而导致引发 RowNotInTableException

Private Sub DemonstrateRowNotInTableException()
    ' Create a DataTable with one column and ten rows.      
    Dim table As New DataTable("NewTable")
    Dim column As New DataColumn("NewColumn")
    table.Columns.Add(column)

    Dim newRow As DataRow
    Dim i As Integer
    For i = 0 To 9
        newRow = table.NewRow()
        newRow("NewColumn") = i
        table.Rows.Add(newRow)
    Next i

    Try
        ' Remove a row and invoke AcceptChanges.
        Dim removedRow As DataRow = table.Rows(9)
        removedRow.Delete()
        removedRow.AcceptChanges()
    
    Catch rowException As System.Data.RowNotInTableException
        Console.WriteLine("Row not in table")
    End Try
End Sub 
private void DemonstrateRowNotInTableException()
{
    // Create a DataTable with one column and ten rows.      
    DataTable table = new DataTable("NewTable");
    DataColumn column = new DataColumn("NewColumn");
    table.Columns.Add(column);

    DataRow newRow;
    for(int i = 0;i <10;i++)
    {
        newRow = table.NewRow();
        newRow["NewColumn"] = i;
        table.Rows.Add(newRow);
    }
    try
    {
        // Remove a row and invoke AcceptChanges.
        DataRow removedRow = table.Rows[9];
        removedRow.Delete();
        removedRow.AcceptChanges();
 
    }
    catch(System.Data.RowNotInTableException rowException)
    {
        Console.WriteLine("Row not in table");
    }
}

继承层次结构

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

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

RowNotInTableException 成员
System.Data 命名空间