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 方法來判斷 rows 集合是否包含數據列。 如果是,則會 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 方法,一次移除集合的所有成員。

適用於

另請參閱