vb连接数据库查询时,提示“至少有一个参数没被指定值”是怎么回事?

来源:百度知道 编辑:UC知道 时间:2024/05/31 23:38:07
Private Sub Command1_Click()
Dim x As String, y As String
Text1.Text = x
Text2.Text = y
Adodc1.RecordSource = "select * from 表1 where 学号>=x and 学号<=y"
sql = "select * from 表1 where 学号>=" & x & " and 学号<=" & y & ""
Adodc1.Refresh
End Sub
还是不行啊!!

帮你改了,看可以吗?

Private Sub Command1_Click()
Dim x As String, y As String, sql As String
x = Text1.Text
y = Text2.Text
sql = "select * from 表1 where 学号>='" & x & "' and 学号<='" & y & "'"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\数据库名称.mdb"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = sql
Adodc1.Refresh
End Sub

数据库设置了吗?

错误的意思是说,你的SQL语句被列出来的字段,有一个没有给它赋值变量

代码修改如下,注意双引号与单引号
Private Sub Command1_Click()
Dim x As String, y As String
x=Text1.Text
y=Text2.Text
Adodc1.RecordSource = "select * from 表1 where 学号>='" & x & "' and 学号<='" & y & "'"
sql = "select * from 表1 where 学号>='" & x & "' and 学号<='" & y & "'"
Adodc1.Refresh
End