I am trying to fill the data for 3 BOs which will be used in a report, I am trying to use the BO.FillMultipleDataTables to get the data, but when creating the SQL for the grand child, I don't know how to reference the PK value in the SQL statement. Here my code for Parent ->Child:
Public Shared Function ServiceCallMaintenance_AllData(ByVal PK_ServiceCalls As Integer, ByVal includeServiceCallRecord As Boolean) As SqlCommand '-- Establish Locals Dim cmd As New SqlCommand() '-- Determine if the Service Call record will be included If includeServiceCallRecord Then cmd.CommandText =
"SELECT dbo.ServiceCalls.* FROM dbo.ServiceCalls WHERE dbo.ServiceCalls.PK_ServiceCalls = @PK_ServiceCalls;" End If '-- Add the Appliances query for the selected Service Call, ordered by the Appliance Service Date. cmd.CommandText &=
"SELECT dbo.SC_Appliances.* FROM dbo.ServiceCalls " & _"INNER JOIN dbo.SC_Appliances ON (dbo.ServiceCalls.PK_ServiceCalls = dbo.SC_Appliances.FK_ServiceCalls) " & _"WHERE (dbo.SC_Appliances.FK_ServiceCalls = @PK_ServiceCalls)" & _"ORDER BY dbo.SC_Appliances.ServicedDate;" '-- Create the parms cmd.Parameters.AddWithValue(
"@PK_ServiceCalls", PK_ServiceCalls).SqlDbType = SqlDbType.Int '-- Return the results Return cmdEnd Function
This code works fine, but if I want to add a grandchild table SC_AppliancesItems which is related to SC_Appliances I don't know to make a reference to SC_Appliances.PK_SC_Appliances in the SQL statement to get all related records to fill the grandchild BO.
How can I accomplish that?
Please see attached relation diagram.