DataRowCollection.Remove(DataRow) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的 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)
參數
範例
以下範例使用 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 方法一次移除所有集合成員。