在vb6中选择组合框的值后自动获取文本框的值

时间:2013-03-24 10:01:08

标签: mysql database vb6 combobox

我有一个包含6列的表products,其中包含 PRICE 列。我想要达到的目的是:

  • 当我从组合框中选择一个值时,下一个价格的文本框将自动从数据库表products填充。

Ex:表产品

ProductName     Price
Mango           12
Apple           15

组合框值:

Mango
Apple

组合框文本框值:

Mango

PRICE 文本框值自动填充:

12

Tried Code:

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

我整天都在尝试这个,但这不起作用,如何纠正这个?真的很困惑。

1 个答案:

答案 0 :(得分:2)

试试这个:这个serrve作为样本......希望它有所帮助

Private sub CboiPAQ_click()
Set rsiPAQs = New ADODB.Recordset 
With rsiPAQs 
.ActiveConnection = cnMHS 
.CursorLocation = adUseClient 
.CursorType = adOpenStatic 
.LockType = adLockPessimistic 
.Source = "SELECT location FROM iPAQs WHERE iPAQ=" & "'" & CboiPAQ.text & "'" 
.Open 
txtbox.text=rsiPAQs("location")
End With 
End sub