VB 删除ACCESS数据库中的记录 delete from FIXALARMS where ALM_DATELAST
上面的语句运行出错,FIXALARMS是ACCESS数据库中的表名。DimYAsIntegerDimMAsIntegerDimDAsIntegerDimTIMESTRAs...
上面的语句运行出错,FIXALARMS是ACCESS数据库中的表名。
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim TIMESTR As Date
Dim MSG
Dim gg As Integer
Y = Year(Now())
M = Month(Now())
D = Day(Now())
TIMESTR = DateSerial(Y, M, D)
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,TIMESTR)"
为什么运行时提示有值没给定呢。ALM_DATELAST 是我表中的莫个列的名称。 展开
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim TIMESTR As Date
Dim MSG
Dim gg As Integer
Y = Year(Now())
M = Month(Now())
D = Day(Now())
TIMESTR = DateSerial(Y, M, D)
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,TIMESTR)"
为什么运行时提示有值没给定呢。ALM_DATELAST 是我表中的莫个列的名称。 展开
3个回答
展开全部
最后一句:
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,'" & TIMESTR & "'"
TIMESTR是VB里面定义的,SQL语句认不得它。
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,'" & TIMESTR & "'"
TIMESTR是VB里面定义的,SQL语句认不得它。
更多追问追答
追问
那DATEADD是VB里面的函数,SQL语句认得不??
追答
前面漏了一个括号,应该是:
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,'" & TIMESTR & "')"
认得,你看双引号的位置就知道了,双引号内的直接把字符串发到SQL服务器,双引号外的是表达式,把表达式的结果转为字符串发到SQL服务器,所以那句话的结果就是:
delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,'2011-4-19')
而你原先的结果是:
delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,TIMESTR)
展开全部
最后一句出错(sql语句缺乏元素),应该在delete和from两个单词中间加上一个星号,即
conn.Execute "delete * from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,TIMESTR)"
conn.Execute "delete * from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,TIMESTR)"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
最后一句也可以是
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,#" & TIMESTR & "#"
单引号也行
conn.Execute "delete from FIXALARMS where ALM_DATELAST < DATEADD(M,-1,#" & TIMESTR & "#"
单引号也行
追问
还不行,提示至少有一个参数没有赋值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询