vb中数据查询语句
PrivateSubcmdYK_Click()lst1.ClearLabel2.Caption=""Label3.Caption=""Label4.Caption=""D...
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
c = K1B
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
我就是想通过变量来查询,也就是说我想要C按我需要是输入而变的
现在就随便搞个C,进去但后面SQL的值就不一样了,不能查询了, 展开
lst1.Clear
Label2.Caption = ""
Label3.Caption = ""
Label4.Caption = ""
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim c As String
c = K1B
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
我就是想通过变量来查询,也就是说我想要C按我需要是输入而变的
现在就随便搞个C,进去但后面SQL的值就不一样了,不能查询了, 展开
展开全部
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
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 & "'"
就行了.
然后你把
sql = "select * from 遥控代换表 where 遥控型号=c"
换成
sql = "select * from 遥控代换表 where 遥控型号='" & C & "'"
就行了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把c定义成变量,修改这里就可以了
sql = "select * from 遥控代换表 where 遥控型号='" & c & "'"
注意格式
'" & c & "'是遥控型号是字符类型
如果遥控型号是数字类型去掉两边的单引号 '
sql = "select * from 遥控代换表 where 遥控型号='" & c & "'"
注意格式
'" & c & "'是遥控型号是字符类型
如果遥控型号是数字类型去掉两边的单引号 '
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询