asp获取每天数据库新增加的记录并进行判断,如果大于某个设定的数据,则停止添加数据,否则的话继续添加。

麻烦大侠们把代码贴出来,菜鸟我不懂,谢谢

select * from news where datediff("d",tdate,getdate())=0

其在tdate则为信息添加时间,datediff("d",tdate,getdate())=0的意思为添加时间跟今天的时间是一天的

在ASP在这样写的
set rs=server.CreateObject("adodb.recordset")
sql="select * from news where datediff(""d"",tdate,'"&now()&"')=0 "
rs.open sql,conn,1,3
if not rs.eof then
if rs.recordcount>10 then '比如一天最多录入10条
response.Write("<script>alert('一天最多录入10条信息');history.back();</script>")
response.End()
else
'这里就写添加信息的哦,我建议你这里最好是对函数的调用,newsadd则为信息添加的函数
call newsadd()
end if
'这里也添加信息的哦,我建议你这里最好是对函数的调用,newsadd则为信息添加的函数
call newsadd()
end if

sub newsadd()
set rs1=server.CreateObject("adodb.recordset")
sql1="select * from news"
rs1.open sql1,conn,1,3
rs1.addnew
rs1("title")=request("title")
rs1("tdate")=now()
rs1.update
response.Write("<script>alert('信息添加成功');window.location='news_list.asp';</script>")
response.End()
end sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-01
首先,在数据库中必须有个存放时间的字段,如times。然后,获取当前的时间,比较这两个时间差值为0的记录(同一天)数量,根据此数值判断是不允许添加还是继续添加。代码示例:
if act="add" then '新增记录
num=conn.execute("select count(id) from table where DateDiff('d',times,year(now()))=0")(0)
if num>=50 then
response.write("alert('sorry!您几天已经添加了50条记录了!');")
connclose()
response.end()
else
'写入数据库
end if
end if

参考资料:http://www.webs-oa.com

第2个回答  2011-09-01
每次添加数据库之前 先 select count(*) from table 判断当前取到的值是否大于你设定的就可以了追问

这个是获取数据库表总记录,我要获取的是当天新站的记录数,谢谢

追答

那就加个判断啊 select count(*) from table where 日期 = getdate()

第3个回答  2011-09-01
在asp页面写个if语句,判断是否大于或小于那个设定数据,如果小于将数据传到插入数据页面,大于就传到其它页面。追问

麻烦大侠们把代码贴出来,菜鸟我不懂,谢谢

相似回答