DataRelation with 3 tables

N

No One

Hi,
I'm trying to setup two DataRelations for the 3 tables in my application.
The first table is the master, the 2nd relates to the master based on the
selected record and the third relates to the second based on the selected
record. The problem I'm having is the third table filters based on the
selected record of the main table and not the child dataset. Does anyone
know how to implement a master/detail with 3 levels with DataRelation
objects or suggest a better way to do it. Below is the code I'm using.

Thanks for your help.


Public Sub LoadDataset()

Dim SqlServer As New SqlServer
Dim TableName() As String = {"JobSummary"}
Dim DBConnectionString As String =
System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString")

TableName(0) = "Job"
SqlServer.FillDataset(DBConnectionString, "GetJobsNotCompleted", FDataset,
TableName, FMachineName)

TableName(0) = "WorkOrder"
SqlServer.FillDataset(DBConnectionString, CommandType.Text, _
"SELECT * from fl_Work_Order_Summary " & _
"WHERE MachineID = " & FMachineName, FDataset, TableName)

TableName(0) = "Item"
SqlServer.FillDataset(DBConnectionString, CommandType.Text, _
"Select * from fl_Item_Summary " & _
"WHERE MachineID = " & FMachineName, FDataset, TableName)

FDataset.Relations.Add("JobWorkOrders",
FDataset.Tables("Job").Columns("JobID"),
FDataset.Tables("WorkOrder").Columns("JobID"), False)

FDataset.Relations.Add("WorkOrderItems",
FDataset.Tables("WorkOrder").Columns("OrderID"),
FDataset.Tables("Item").Columns("OrderID"), False)

End Sub

Private Sub MainForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

LoadDataset()

DataGrid1.DataSource = FDataset
DataGrid1.DataMember = "Job"

DataGrid2.DataSource = FDataset
DataGrid2.DataMember = "Job.JobWorkOrders"

DataGrid3.DataSource = FDataset
DataGrid3.DataMember = "WorkOrder.WorkOrderItems"

End Sub
 
N

No One

Sorry, I found the answer to my own question. FYI; all I had to do was
change the line:
DataGrid3.DataMember = "WorkOrder.WorkOrderItems"
to
DataGrid3.DataMember = "Job.JobWorkOrders.WorkOrderItems"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top