locked
Removing A Data Relation In VB2019 RRS feed

  • Question

  • Hi:

    How would I dispose of the data relation so that I can dispose of the

    two datatables?

          'Create A DataRelation.
            Dim data_relation As New _
            DataRelation("SE_CS", dsPSB1.Tables("dtSE").Columns("SE_KEY"), dsPSB1.Tables("dtCS").Columns("CS_SE_KEY"))
            dsPSB1.Relations.Add(data_relation)

        Remove A DataRelation Called "SE"CS"

         'Remove DataTables From The DataSet.
         dsPSB.Tables.Remove("dtSE")

         dsPSB.Tables.Remove("dtCS")

         'Dispose Of The Form.
         Me.Dispose()



    Wednesday, May 13, 2020 7:00 PM

Answers

  • Try this

    Remove any constraints e.g.

    ds.Tables("Your table name").Constraints.Remove("Constraint name goes here")

    Then remove the relationship

    If ds.Relations.Contains("MyRelation") Then
    	ds.Relations.Remove("MyDataRelation")
    End If
    Untested, done in notepad.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, May 13, 2020 9:43 PM