我在同一个数据库中有两个表:
order_no (primary key)
和 cust_name
order_no (foreign key)
(单个订单中订购的每个食品项目也有重复条目)、table_no
、items
、date
、cust_name
等等...我的问题是:如何使用table1的主键在列表框和数据网格或文本框中显示记录
order_no
这样我就可以获得在table2中分配了具有相同订单号的外键的所有记录
我正在使用 Visual Basic 6.0
尝试这样的事情
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