I have two tables in same database:
order_no (primary key)
and cust_name
order_no (foreign key)
(which also have duplicates entry per food item ordered in single order), table_no
, items
, date
, cust_name
and so on...My question is: how can I show the records in listbox and datagrid or in textbox using table1's primary key order_no
so I can get all the records which have assigned the foreign key with same order number in table2
I am using Visual Basic 6.0
Try something like this
Private Sub mLoadData(lOrder_no As Long)
' add a reference to Microsoft ActiveX Data Objects 2.8 Library
' add a MSHFLXGD (Microsoft Hierarchical FlexGrid) control named grData to form
Dim rc As ADODB.Recordset
Dim db As New ADODB.Connection
Dim sConnString As String, sSQL As String
'sConnString = create a connection string according to your database - https://www.connectionstrings.com/
db.Open sConnString
sSQL = "SELECT * FROM table2 WHERE order_no =" & lOrder_no
Set rc = db.Execute(sSQL)
Set grData.DataSource = rc
End Sub