Alex
Alex

Reputation: 4938

How to Fetch DataTable1 & DataTable2 Information using Relationship

Goal

I want to access the information of my child's table via the parent table. Using the image below, we can see that I have Conveying Solutions and for every Conveying Solution, I will have one or more Conveyor Functions related to it.

Keep in mind, I'm not even sure my relationship has been done correctly below... I'm new to this.

Relationship


Attempt

I load the information into my DataTables (this works correctly) on the form load. I then set my DataView's table to my Conveying Solution's DataTable and set my DataView as the DataSource of my DataGridView.

Public Class Form1
    Private DataView1 As New DataView


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        clsConveyingSolution.LoadConveyingSolutions()
        clsConveyorFunction.LoadConveyorFunctions()

        Try
            DataView1.Table = HunterMgmt.dtConveyingSolutions
            DataGridView1.DataSource = DataView1
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

I'd like to perform some sort of join and have access to the information of both tables using the relationship that I established.

Upvotes: 1

Views: 78

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

If you want to join the data from the two tables then you have two main choices:

  1. Add a new DataTable and table adapter to your DataSet based on a query that performs the join. You would then treat that DataTable and table adapter the same way you would any other.
  2. Use LINQ or some manual process to create a new list that joins the data from the rows of your existing DataTables.

Upvotes: 1

Related Questions