日期:2014-05-17  浏览次数:20872 次

为什么这段代码不能检测相同日期禁止录入?请看看有什么不妥!
数据库   weather
字段       tq_date     格式为: "短日期 "     2007-8-14

我想禁止录入相同日期看看下面代码为什么不能判断?

<%
set   rs   =   server.CreateObject   ( "adodb.recordset ")  
sql   =   "select   *   from   [weather]   where   tq_date= "&request( "tq_date ")

rs.Open   sql,conn,1,1  

if   rs.bof=false   and   rs.eof=false   then

response.write   " <script   language=javascript> alert( '温馨提示:日期重复,禁止录入! ');history.go(-1); </script> "
rs.close

else

set   rs   =   server.CreateObject   ( "adodb.recordset ")
sql   =   "select   *   from   weather "
rs.Open   sql,conn,1,3
rs.AddNew  
rs( "tq_date ")   =   Request( "tq_date ")  
rs( "tqxx1 ")   =   Request( "tqxx1 ")  
rs( "tqxx_img ")   =   Request( "tqxx_img ")  
rs( "qiwen1 ")   =   Request( "qiwen1 ")  
rs( "qiwen2 ")   =   Request( "qiwen2 ")  
rs( "windy ")   =   Request( "windy ")  
rs.Update  
rs.Close  
set   rs=nothing  
end   if
%>  

<script   language=javascript>    
alert(   "录入成功 "     );
location.href   =   "login.asp "    
</script>
<%end   if%>
<%end   sub%>


------解决方案--------------------
你用的数据库是access还是sqlserver?
access:
sql = "select * from [weather] where tq_date=# " & request( "tq_date ") & "# "

sqlserver:
sql = "select * from [weather] where tq_date= ' "&request( "tq_date ") & " ' "

试一下看