vb 中使用sql语句时遇到的一个问题
用vb实现一个查询,我写的查询语句如下:select*from"&combo1.text&"where型号='"&text1.text"'",myconn,adOpenD...
用vb实现一个查询,我写的查询语句如下:
select * from "& combo1.text& " where 型号= '"&text1.text"'", myconn, adOpenDynamic
具体说明:我想在text1中输入型号名称,在combo1中选择具体的表,然后实现查询。但是提示:缺少语句结束
我没看出哪儿错了!
高手指点一下!
顺便贴出其他的代码:
Option Explicit
Private myconn As New ADODB.Connection
Private myrecord As New ADODB.Recordset
Private Sub Combo1_Change()
End Sub
Private Sub Command1_Click()
myrecord.Open "select * from "& combo1.text &" where 型号= '"&text1.text"'", myconn, adOpenDynamic, adLockBatchOptimistic
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "二极管"
.AddItem "三极管"
End With
Set myconn = New ADODB.Connection
Set myrecord = New ADODB.Recordset
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\毕业设计\查询系统\sysdata.mdb;Persist Security Info=False"
myconn.Open
End Sub
(sql语句都是在一行的,这里显示不一样)
strsql = "select * from " & Combo1.Text & " where 型号='" & Text1.Text & "'"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strsql
If Adodc1.Recordset.RecordCount <= 0 Then
MsgBox "未找到你需要的数据!", vbInformation + vbOKOnly, "数据库信息"
Exit Sub
Else
Set DataGrid1.DataSource = Adodc1
End Sub
又出错了!提示是Adodc1.Recordset.RecordCount <= 0这句有毛病!
我快折腾死了,就是这个查询!有高手帮我谢谢吧!!
我引用ado控件,然后绑定到datagrid上去! 展开
select * from "& combo1.text& " where 型号= '"&text1.text"'", myconn, adOpenDynamic
具体说明:我想在text1中输入型号名称,在combo1中选择具体的表,然后实现查询。但是提示:缺少语句结束
我没看出哪儿错了!
高手指点一下!
顺便贴出其他的代码:
Option Explicit
Private myconn As New ADODB.Connection
Private myrecord As New ADODB.Recordset
Private Sub Combo1_Change()
End Sub
Private Sub Command1_Click()
myrecord.Open "select * from "& combo1.text &" where 型号= '"&text1.text"'", myconn, adOpenDynamic, adLockBatchOptimistic
End Sub
Private Sub Form_Load()
With Combo1
.AddItem "二极管"
.AddItem "三极管"
End With
Set myconn = New ADODB.Connection
Set myrecord = New ADODB.Recordset
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\毕业设计\查询系统\sysdata.mdb;Persist Security Info=False"
myconn.Open
End Sub
(sql语句都是在一行的,这里显示不一样)
strsql = "select * from " & Combo1.Text & " where 型号='" & Text1.Text & "'"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strsql
If Adodc1.Recordset.RecordCount <= 0 Then
MsgBox "未找到你需要的数据!", vbInformation + vbOKOnly, "数据库信息"
Exit Sub
Else
Set DataGrid1.DataSource = Adodc1
End Sub
又出错了!提示是Adodc1.Recordset.RecordCount <= 0这句有毛病!
我快折腾死了,就是这个查询!有高手帮我谢谢吧!!
我引用ado控件,然后绑定到datagrid上去! 展开
3个回答
展开全部
myrecord.Open "select * from "& combo1.text &" where 型号= '"&text1.text"'", myconn, adOpenDynamic, adLockBatchOptimistic
where 型号= '"&text1.text&"'", myconn, 3,3
where 型号= '"&text1.text&"'", myconn, 3,3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
myrecord.Open "select * from "& combo1.text &" where 型号= '"&text1.text"'", myconn, adOpenDynamic, adLockBatchOptimistic
&text1.text"'"有错
应写为:
where 型号='" & text1.text & "'",
&text1.text"'"有错
应写为:
where 型号='" & text1.text & "'",
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询