locked
Data relation with 3 tables RRS feed

  • Question

  • Hallo,

    I have 2 combo boxes and i want to filter or show the data in a data grid view based on the 2 combo boxes, i know i can filter the table or binding source in many ways but just want to know if it possible to do it via data relations. 

    I want to show the table 3 in data grid view based on the value from table 1 & 2 how to add data relation for the following setup if possible.

     DS.Relations.Add("Tab1toTab3", Tables("Tab1").Columns("Col1"), Tables("Tab3").Columns("Col1"))
     DS.Relations.Add("Tab2toTab3", Tables("Tab2").Columns("Col2"), Tables("Tab3").Columns("Col3"))
    
    
    Dim BS1 As New BindingSource With {.DataSource = DS, .DataMember = "table1"}
    Dim BS2 As New BindingSource With {.DataSource = BS1, .DataMember = "Tab1toTab3"}
    Dim BS3 As New BindingSource With {.DataSource = BS2, .DataMember = "Tab2toTab3"}  '''this does not work

    is it possible to something like this? thanks

    Monday, August 24, 2020 4:36 PM

All replies

  • I have a code sample that does three tables. See the following TechNet article (skip down to base read operation) and GitHub source code. SQL-Server is the database but by changing the data provider this will work on any database.

    EDIT: Note the top two DataGridView in your case would be ComboBox controls.


    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


    Monday, August 24, 2020 4:53 PM
  • it looks like from your example. it is like customers -> orders-> order details but my setup is little different still don't know how i can use your example.

    And i get following error when i try to start the project. i don't know what to do. 

    Monday, August 24, 2020 5:46 PM
  • This shows the startup project, right click on it in Visual Studio and mark it the startup project.

    A little background, the source code does a classic master/detail where details is the master to order details.

    I used three DataGridView controls, you would use two ComboBox controls and one DataGridView.


    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

    Monday, August 24, 2020 5:57 PM