Hi, I have a form with multiple tables.
when I add rors into the tables I Use code like this:

Dim n As Integer = 0
        For Each copyRows1 In copyRows
            Dim newOrdreRow As DataRow = Kalkyle1DataSet.Tables("Ordre").NewRow()
            Dim Ordredato As String = Kalkyle1DataSet.Tables("Ordre").Rows(n).Item("Ordedato")

where I add new rows also addin a OrdreID as Foreign Key.


How do I Delete all records in the tabel with the foreign key = * ?

* = a number I choose

Loop through the Kalkyle1DataSet.Tables("Ordre").Rows collection until you find the row containg the foreign key you are looking for.
Then you can use the method Remove to remove the row from the table.
Note that I've chosen to run the loop backwards in order to maintain the zero-based collection.

Dim row As DataRow

For i As Integer = Kalkyle1DataSet.Tables("Ordre").Rows.Count -1 To 0 Step -1
   If Kalkyle1DataSet.Tables("Ordre").Rows(i).Item("Ordedato") = <your number> Then
      row = Kalkyle1DataSet.Tables("Ordre").Rows(i)
      Kalkyle1DataSet.Tables("Ordre").Rows.Remove(row)
   End If
Next
Kalkyle1DataSet.Tables("Ordre").AcceptChanges()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.