DataRowCollection.Remove(DataRow) Metod

Definition

Tar bort den angivna DataRow från samlingen.

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)

Parametrar

row
DataRow

Att DataRow ta bort.

Exempel

I följande exempel används Remove metoden för att ta bort en hittad rad i ett DataRowCollection objekt. Exemplet använder Contains först metoden för att avgöra om radsamlingen innehåller en rad. Om den gör Find det används metoden för att hitta den specifika raden, och Remove metoden används sedan för att ta bort raden.

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

Kommentarer

När en rad tas bort går alla data på den raden förlorade. Du kan också anropa Delete -metoden för DataRow klassen för att markera en rad för borttagning. Samtal Remove är detsamma som att ringa Delete och sedan anropa AcceptChanges.

Remove ska inte anropas i en foreach-loop när du itererar genom ett DataRowCollection objekt. Remove ändrar samlingens tillstånd.

Du kan också använda Clear metoden för att ta bort alla medlemmar i samlingen samtidigt.

Gäller för

Se även