Private Sub cmdYK_Click()
lst1.Clear
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim c As String
cn.Open "provider=microsoft.jet.oledb.4.0; data source=D:\VB\销售软件\data\1.mdb"
Dim rs As ADODB.Recordset
Dim sql As String
c="K1B"
sql = "select * from 遥控代换表 where 遥控型号='" & c & "'"
Set rs = New ADODB.Recordset
rs.Open sql, cn, adOpenForwardOnly, adLockOptimistic
Label2.Caption = rs("电视品牌")
Label3.Caption = rs("遥控芯片")
Label4.Caption = rs("红外系统码")
Do While Not rs.EOF
lst1.AddItem rs("遥控型号")
rs.MoveNext
Loop
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
cn.Open "provider=microsoft.jet.oledb.4.0; data source=D:\VB\销售软件\data\1.mdb"
换成相对地址!
首先,你建一个文本框控件,让它作为C的值,即把原来的C=K1B换成C=textbox1.text,
然后你把
sql = "select * from 遥控代换表 where 遥控型号=c"
换成
sql = "select * from 遥控代换表 where 遥控型号='" & C & "'"
就行了.
把c定义成变量,修改这里就可以了
sql = "select * from 遥控代换表 where 遥控型号='" & c & "'"
注意格式
'" & c & "'是遥控型号是字符类型
如果遥控型号是数字类型去掉两边的单引号 '