0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Oxiegen
0

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()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.