sql查询的问题,急于解决,请指教!

susanxiaoshan 2003-01-04 10:01:17
我有两个窗体,第一个窗体里是一些查询的功能,其结果显示在第二个窗体里的datagrid里。现在我在第二个窗体里加一个command和两个label控件,希望在按下command控件后,label里出现我需要的内容,代码如下:
Private Sub Command1_Click()
dim strsql,strsql1,strsql2 as string

strsql = "select * from box where 1=1 " & Trim(ss)
strsql1 = strsql & "and 返回日期=''"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strsql4
Adodc1.Refresh
Label1.Caption = "共计:" + Str(Adodc1.Recordset.RecordCount) + "份"
strsql1 = strsql & " and 返回日期=''" & "and DateDiff('d', 交接日期, today) " & "<= 15"
Adodc1.RecordSource = strsql1
Adodc1.Refresh
Label1.Caption = "周期《2周:" + Str(Adodc1.Recordset.RecordCount) + "份"

End Sub

其中Trim(ss)是我在第一个通过property let方法引用过来的第一个窗体的查询条件,已经证明是完全正确的。但当我执行上面代码时,提示对话框显示“语法错误(操作符丢失)在查询表达式‘1=1 and 返回日期='''中。其中“返回日期”和“交接日期”都是我与adodc1链接的access表中的两个字段。是否在这个程序段里要对这两个字段进行重新定义?这段程序还有其他错误吗?

谢谢指教!!
...全文
23 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxun 2003-01-07
  • 打赏
  • 举报
回复
用debug.print列出strsql的值,再去个个验证语法正确性
Jim_OU 2003-01-06
  • 打赏
  • 举报
回复
你的 “=” 号不会是特别长吧,我还以为你用了两个 “=” 号
龙华 2003-01-06
  • 打赏
  • 举报
回复
strsql1 = strsql & " and 返回日期=''" & "and DateDiff('d', 交接日期, today) "
这里有错,你的“and DateDiff”前面少了一个空格。
of123 2003-01-06
  • 打赏
  • 举报
回复
1=1 是什么?
hitwy1979 2003-01-06
  • 打赏
  • 举报
回复
吧你的sql语句显示出来,然后考到查询分析器上执行一下,就知道是不是错了
bobob 2003-01-06
  • 打赏
  • 举报
回复
trim(ss)到底是什么格式?
sql里面的'检查是很严格的,你的一定是'出了问题。

chenyu5188 2003-01-06
  • 打赏
  • 举报
回复
strsql1 = strsql & " and 返回日期='' and DateDiff('d', 交接日期, today) <= 15"
susanxiaoshan 2003-01-06
  • 打赏
  • 举报
回复
我有两个窗体,第一个窗体里是一些查询的功能,其结果显示在第二个窗体里的datagrid里。现在我在第二个窗体里加一个command和两个label控件,希望在按下command控件后,label里出现我需要的内容,代码如下:
Private Sub Command1_Click()
dim strsql,strsql4 as string

strsql = "select * from box where 1=1 " & Trim(ss)
strsql1 = strsql & " and 返回日期=''"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strsql4
Adodc1.Refresh
Label1.Caption = "共计:" + Str(Adodc1.Recordset.RecordCount) + "份"
strsql1 = strsql & " and 返回日期=''" & "and DateDiff('d', 交接日期, today) " & "<= 15"
Adodc1.RecordSource = strsql1
Adodc1.Refresh
Label1.Caption = "周期《2周:" + Str(Adodc1.Recordset.RecordCount) + "份"

End Sub

其中Trim(ss)是我在第一个通过property let方法引用过来的第一个窗体的查询条件,已经证明是完全正确的。但当我执行上面代码时,提示对话框显示“语法错误(操作符丢失)在查询表达式‘1=1 and 返回日期='''中。其中“返回日期”和“交接日期”都是我与adodc1链接的access表中的两个字段。是否在这个程序段里要对这两个字段进行重新定义?这段程序还有其他错误吗?

我重新把我的问题写了一遍,1=1是一个恒等式,起一个连接后面条件的作用,而trim(ss)肯定没错,因为我前面的查询已经用到了这个,且运行正确。
litterlobster 2003-01-06
  • 打赏
  • 举报
回复
dim strsql as string
dim strsql1 as string
dim strsql2 as string
wangweicai 2003-01-06
  • 打赏
  • 举报
回复
dim strsql,strsql1,strsql2 as string
此处不标准:
dim strsql as string,strsql1as string,strsql2 as string

dim strsql as string
dim strsql1 as string
dim strsql2 as string
redwrite 2003-01-06
  • 打赏
  • 举报
回复
可能原因就是这个吧
xuxun 2003-01-05
  • 打赏
  • 举报
回复
strsql1 = strsql & " and 返回日期=''" & "and DateDiff('d', 交接日期, today) "
To
strsql1 = strsql & " and 返回日期=''" & " and DateDiff('d', 交接日期, today) "
在and前加一个空格试试
susanxiaoshan 2003-01-05
  • 打赏
  • 举报
回复
问题是我执行到第一个查询语句时,就出错了,错误不是因为and前少一个空格的原因。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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