2013-03-24 71 views
1

我有一个表products,其中有6列,包括列价格。我想才达到的是:在vb6中选择组合框的值后自动获取文本框的值

  • 当我选择下拉菜单中的下一个文本框是价格将自动从数据库表products填补的值。

例:表产品

ProductName  Price 
Mango   12 
Apple   15 

组合框的值:

Mango 
Apple 

组合框的文本框的值:

Mango 

价格文本框的值自动填入与:

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 

我想这一个整天但这不工作,如何改正这个人真的糊涂到这个?

+0

尝试txtPrice = Rs.Fields(0).value的 – 2013-03-24 10:07:27

+0

它的主要错误,请帮我 – 2013-03-24 10:40:56

+0

您的查询字符串是错的太 - 尝试类似'.CommandText =“选择产品产品的价格where productname ='”&txtProdname.txt&“'”' – 2013-03-24 10:45:57

回答

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 
+0

哇!真棒!谢谢! – 2013-03-24 12:34:03

相关问题