[英]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:我在同一个数据库中有两个表:
order_no(primery key)
and cust_name
table1 包含order_no(primery key)
和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... table2 包含order_no(foreign key)
(在单个订单中订购的每个食品项目也有重复条目)、 table_no
、 items
、 date
、 cust_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.