【问题标题】:Automatically get the value of textbox after selecting value of combobox in vb6vb6中选择combobox的值后自动获取textbox的值
【发布时间】: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


【解决方案1】:

试试这个:这个作为示例......希望它有所帮助

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2020-05-17
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多