DataRowCollection.Remove(DataRow) 方法

定义

从集合中移除指定的 DataRow 值。

public:
 void Remove(System::Data::DataRow ^ row);
public void Remove(System.Data.DataRow row);
member this.Remove : System.Data.DataRow -> unit
Public Sub Remove (row As DataRow)

参数

row
DataRow

DataRow 删除的。

示例

以下示例使用 Remove 该方法删除对象中找到的 DataRowCollection 行。 该示例首先使用 Contains 该方法来确定行集合是否包含行。 如果这样做,则 Find 该方法用于查找特定行, Remove 然后使用该方法删除该行。

Private Sub RemoveFoundRow(ByVal table As DataTable)
    Dim rowCollection As DataRowCollection = table.Rows

    ' Test to see if the collection contains the value.
    If rowCollection.Contains(TextBox1.Text) Then
        Dim foundRow As DataRow = rowCollection.Find(TextBox1.Text)
        rowCollection.Remove(foundRow)
        Console.WriteLine("Row Deleted")
    Else
        Console.WriteLine("No such row found.")
    End If
 End Sub

注解

删除行后,该行中的所有数据都将丢失。 还可以调用 Delete 类的方法,以仅标记要删除的 DataRow 行。 呼叫 Remove 与调用 Delete 和调用 AcceptChanges相同。

Remove 在循环访问 DataRowCollection 对象时,不应在 foreach 循环中调用。 Remove 修改集合的状态。

还可以使用 Clear 该方法一次性删除集合的所有成员。

适用于

另请参阅