各位高手!这句SQL语句如何写啊?我的语句总是出错。

05108807619 2004-04-26 09:39:34
我要做一个查询:从数据表中的某一个数值段中记录。

我在窗体中设定数值的开始由txtBegin.text设定,结束由txtEnd.text设定,然后我的语句这样写:

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\ReportVariables.mdb;Mode=Read"
m_Connection.Open strConnect
SQL = "Select * from tblSampleData Where LongField >= '" + txtBegin.Text + "' and Longfiled <= '" + txtEnd.Text + "'"
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic

但是我在执行时总是会在最后一句出错。错误的提示是:实时错误-2147217904(80040e10)至少一个参数没有被指定值

但是上面的那个代码,我如果用具体数值代替其中的'" + txtBegin.Text + "'和'" + txtEnd.Text + "',那么这个语句又是可以正常执行的。
请问是什么原因?高手帮忙!谢谢!
...全文
193 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yiway 2004-04-27
  • 打赏
  • 举报
回复
if not IsNumeric(txtBegin.Text) or not IsNumeric(txtBegin.Text) then
msgbox "错误!"
exit sub
end if
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\ReportVariables.mdb;Mode=Read"
m_Connection.Open strConnect
SQL = "Select * from tblSampleData Where LongField >= " + txtBegin.Text + " and Longfiled <= " + txtEnd.Text
adoRS.Open SQL, m_Connection, adOpenDynamic, adLockBatchOptimistic
05108807619 2004-04-27
  • 打赏
  • 举报
回复
感谢各位朋友!我用了Northwolves的办法,可以解决了。
另外,yiway的代码我没有试,但看了一下,应该也是可行的。呵呵。
05108807619 2004-04-27
  • 打赏
  • 举报
回复
TO: northwolves(野性的呼唤)

如果我把你语句中的cdbl去掉,就能执行了!是什么原因啊?
05108807619 2004-04-27
  • 打赏
  • 举报
回复
TO:homeland520(天山之王(哈哈两声说Beybey))
你的代码和我的代码一样引起同样的错误。

TO:northwolves(野性的呼唤)
你的代码会引起这样的错误:实时错误'13'类型不匹配

用between查询会这样麻烦吗?再次拜托各位老大高手了!
flc 2004-04-27
  • 打赏
  • 举报
回复
学习
homeland520 2004-04-26
  • 打赏
  • 举报
回复
什么也不会,来学习了,哈哈
northwolves 2004-04-26
  • 打赏
  • 举报
回复
SQL = "Select * from tblSampleData Where LongField between " + cdbl(txtBegin.Text) + " and "+ cdbl(txtEnd.Text)
homeland520 2004-04-26
  • 打赏
  • 举报
回复
SQL = "Select * from tblSampleData Where LongField >= '"&trim(txtBegin.Text)&"' and Longfiled <= '"&trim(txtEnd.Text)&"'"
happyangelo 2004-04-26
  • 打赏
  • 举报
回复
数值段中的条件值不用家单引号“'”。

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧