简体   繁体   English

如何通过在一个表中使用外键在 Visual Basic 6.0 中使用另一个表中的主键来获取记录

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

i have two tables in same database:我在同一个数据库中有两个表:

  • table1 contains order_no(primery key) and cust_name table1 包含order_no(primery key)cust_name
  • table2 contains 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... table2 包含order_no(foreign key) (在单个订单中订购的每个食品项目也有重复条目)、 table_noitemsdatecust_name等等......

so my question is how can i show the records in listbox and datagrid or in textbox using table1's primery key order_no so i can get all the records which have assigned the foreign key with same order number in table2所以我的问题是如何使用table1的primary key order_no在列表框和数据网格或文本框中显示记录,这样我就可以获得在table2中分配了具有相同订单号的外键的所有记录

i am using visual basic 6.0我正在使用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM