100分求解:ASP中表达式中 'Getdate' 函数未定义?
发布网友
发布时间:2023-09-07 15:16
我来回答
共4个回答
热心网友
时间:2023-09-16 20:09
1。看你数据库连接中用JET,你的是ACCESS是吧?ACCESS没有GetDate()函数。用的是Now()函数。
2。而用了Now后产生的“至少一个参数没有被指定值”是因为可能有其他错误。
你的代码写得有些乱,重复的地方多,调试起来不太容易。
如下,不过有些代码我用...代替了。你自己替换一下。然后看一下Sql输出的是什么值。这样再在ACCESS中去运行一下。
Sql = ""
Sql = Sql & "SELECT TOP " & (Page * Maxperpage) & " AdID, City_OneId, City_TwoId, City_ThreeId, City_One, City_Two, City_Three," & vbCrLf
Sql = Sql & " type_OneId, type_TwoId, type_ThreeId," & vbCrLf
Sql = Sql & " [Color], [Title], [Text], [Date], Pic, Hits, [Money], MoneyDate, [Top], [Hot]" & vbCrLf
Sql = Sql & "FROM China_Data" & vbCrLf
Sql = Sql & "WHERE (Mark = 'yes'" & vbCrLf
If (....) Then
Sql = Sql & "AND (" & vbCrLf
Sql = Sql & " (DateDiff(d, Now(), [Stop]) >= 1)" & vbCrLf
Sql = Sql & " OR (" & vbCrLf
Sql = Sql & " ([Money] > 0)" & vbCrLf
Sql = Sql & " AND (DateDiff(d, Now(), [MoneyDate]) >= 1)" & vbCrLf
Sql = Sql & " )" & vbCrLf
Sql = Sql & ")" & vbCrLf
Else
Sql = Sql & "AND (" & vbCrLf
Sql = Sql & " [stop] >= Date()" & vbCrLf
Sql = Sql & " OR (" & vbCrLf
Sql = Sql & " [Money] > 0" & vbCrLf
Sql = Sql & " AND MoneyDate >= date()" & vbCrLf
Sql = Sql & " )" & vbCrLf
Sql = Sql & ")" & vbCrLf
End If
Sql = Sql & c & t & vbCrLf
Sql = Sql & " ORDER BY [top] DESC"
Select Case OrderType
Case 1
Sql = Sql & ", Adid"
Case 2
Sql = Sql & ", Adid DESC"
Case 3
Sql = Sql & ", hits"
Case 4
Sql = Sql & ", hits DESC"
Case Else
Sql = Sql & ", [money] DESC,Adid DESC"
End Select
If (Not IsObject(Conn) Or Conn Is Nothing) Then DbLink
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.Open Sql,Conn,1,1
If Not Rs.Eof Then Rs.Move (Maxperpage * (page - 1))
IF Not Rs.Eof Then typeData = Rs.Getrows
...
Rs.Close
Set Rs = Nothing
热心网友
时间:2023-09-16 20:09
你没有在函数DateDiff(d,now(),[MoneyDate])中加单引号,注意加上单引号,DateDiff('d',now(),[MoneyDate])表明 是按照日期'd'进行计算时间间隔的。
''注意:在 access中,函数DateDiff('d',now(),[MoneyDate])中第一个参数要加上单引号,否则会发生 至少一个参数没有被指定值。在sql server中函数DateDiff('d',now(),[MoneyDate])第一个参数不需要加单引号的。这是 两个类型的sql语句中的区别。
你的数据库应该是access数据库,把getdate()换成 now(),
现把代码修改如下。运行无误。
Sql = "Select top "&Page*Maxperpage&" adid,City_oneid,City_twoid,City_threeid,City_one,City_two,City_three,type_oneid,type_twoid,type_threeid,[color],[title],[text],[date],pic,hits,[Money],MoneyDate,[Top],[hot] From China_Data Where mark='yes' And (DateDiff('d',now(),[stop])>=1 Or (DateDiff('d',now(),[MoneyDate])>=1 And [Money]>0)) "&c&t&" order by [top] desc"
Else
Sql = "Select top "&Page*Maxperpage&" adid,city_oneid,city_twoid,city_threeid,city_one,city_two,city_three,type_oneid,type_twoid,type_threeid,[color],[title],[text],[date],pic,hits,[Money],MoneyDate,[Top],[hot] From China_Data Where mark='yes' And ([stop]>=Date() Or ([Money]>0 And MoneyDate>=date())) "&c&t&" order by [top] desc"
End If
Select Case OrderType
Case 1
Sql = Sql & ",Adid"
Case 2
Sql = Sql & ",Adid Desc"
Case 3
Sql = Sql & ",hits"
Case 4
Sql = Sql & ",hits Desc"
Case Else
Sql = Sql & ",[money] Desc,Adid Desc"
End Select
If Not IsObject(Conn) Or Conn Is NoThing Then DbLink
Set Rs=server.createobject("adodb.recordset")
Rs.Open Sql,Conn,1,1
If Not Rs.Eof Then Rs.Move (Maxperpage*(page-1))
IF Not Rs.Eof Then typeData=Rs.Getrows
热心网友
时间:2023-09-16 20:10
Sql = "Select top "&Page*Maxperpage&" adid,City_oneid,City_twoid,City_threeid,City_one,City_two,City_three,type_oneid,type_twoid,type_threeid,[color],[title],[text],[date],pic,hits,[Money],MoneyDate,[Top],[hot] From China_Data Where mark='yes' And (DateDiff(d,getDate(),[stop])>=1 Or (DateDiff(d,getDate(),[MoneyDate])>=1 And [Money]>0)) "&c&t&" order by [top] desc"
至少一个参数没有被指定值!
错误一定在sql这个变量里面!
将以下代码放到“Select Case OrderType”前面试试:
response.write sql
response.end
看一下输出的语句,你就知道哪有问题
热心网友
时间:2023-09-16 20:10
是获取时间涵数么