【发布时间】:2013-03-24 10:01:08
【问题描述】:
我有一张表products,有 6 列,包括列 PRICE。我想要实现的是:
- 当我从组合框中选择一个值时,下一个文本框 Price 将自动从数据库表
products中填充。
例如:餐桌用品
ProductName Price
Mango 12
Apple 15
组合框值:
Mango
Apple
组合框文本框值:
Mango
PRICE文本框值自动填充:
12
尝试过的代码:
Private Sub Price()
Set Rs = New ADODB.Recordset
Set Cmd = New ADODB.Command
If txtProdName.txt Is Not Nothing Then
With Cmd
.ActiveConnection = Conn
.CommandType = adCmdText
.CommandText = "SELECT price from products where productname=txtProdname.txt"
Set Rs = .Execute
End With
txtPrice = Rs.Fields
End If
End Sub
我整天都在尝试这个,但这不起作用,如何纠正这个?真的很困惑。
【问题讨论】:
-
试试 txtPrice = Rs.Fields(0).Value
-
它有错误,请帮助我
-
您的查询字符串也错误 - 尝试类似
.CommandText = "SELECT price from products where productname='" & txtProdname.txt & "'" -
错误出现在“If txtProdName.txt Is Not Nothing Then”部分。有什么建议吗?它说“无效使用对象”
-
我的 VB6 生锈了,但像
if Len(txtProdName.txt) > 0这样的东西可能是一个可用的测试。
标签: mysql database vb6 combobox