如何在 visual basic 6.0 中通过使用外键 table 使用主键另一个 table 来获取记录

How to get records by using foreign key in one table using primery key another table in visual basic 6.0

我在同一个数据库中有两个表:

所以我的问题是如何使用表 1 的主键 order_no 在列表框和数据网格或文本框中显示记录,这样我就可以获得在表 2 中分配了具有相同订单号的外键的所有记录

我正在使用 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