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

关于验证重复字段问题,有代码,帮忙看看,谢谢~
帮忙看看这段代码,我输入的是数据库里已经有的IP,可为什么没执行response.redirect   "error.asp?id=003(提示不可重复)这段代码,而且重复的IP还保存到库里了,请指教,谢谢!
<%
set   conn   =   server.createObject( "adodb.connection ")
conn.Open   Application( "dsn ")
set   rs1   =   server.createObject( "adodb.recordset ")
'确保IP段唯一
sql= "select   set_IP   from   setIP   where   set_IP= ' "&T1& " '   "
rs1.open   sql,conn,3,2
num1=rs1.recordcount
'=======验证该ip段是否存在
if   num1   <>   0   then
    response.redirect   "error.asp?id=003 "
else
rs1.addnew
rs1( "set_IP ")   =   request( "T1 ")
  rs1.update
  rs1.close
  set   rs1=nothing
  conn.close
  set   conn   =   nothing
  response.redirect   "index.asp "
  end   if
 
%>


------解决方案--------------------
num1=rs1.recordcount
'=======验证该ip段是否存在
if num1 <> 0 then
response.redirect "error.asp?id=003 "
else
rs1.addnew
rs1( "set_IP ") = request( "T1 ")
rs1.update
rs1.close
set rs1=nothing
conn.close
set conn = nothing
response.redirect "index.asp "
end if


=-----------------

if not rs.eof then
response.write "已经有数据 "
else
conn.execute( "inser into [tb]。。。 ")
end if