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

在ASP中对已有的数据字段进行对比,如果数据存在则报错。我的代码有错,大虾看看
<%
sfzid=request.form( "sfzid ")
set   conn=server.createobject( "adodb.connection ")
conn.open   "driver={microsoft   access   driver   (*.mdb)};dbq= "&server.mappath( "#bm.mdb ")
exec= "select   *   from   info_cs   where   tcy_id   is   not   null   and   name   is   null "
set   rs=server.createobject( "adodb.recordset ")
rs.open   exec,conn,1,3
rs( "name ")=request.form( "name ")
rs( "sex ")=request.form( "sex ")
rs( "sfzid ")=request.form( "sfzid ")
rs( "tel ")=request.form( "tel ")
rs( "adslid ")=request.form( "adslid ")
rs( "tcyid ")=request.form( "tcyid ")
if
exec= "select   sfzid   from   info_cs   where   sfzid= ' "&sfzid& " ' "
response.Write( "该身份证号已被注册 ")
else
rs.update
rs.close
end   if
set   rs=nothing
conn.close
set   conn=nothing
response.redirect   "chaxunid.asp "

这样写有错误。。。那个大虾看看

------解决方案--------------------
exec= "select * from info_cs where sfzid= ' "&sfzid& " ' "
set rs=server.createobject( "adodb.recordset ")
rs.open exec,conn,1,3

if not (rs.eof and rs.bof) then

response.Write( "该身份证号已被注册 ")
response.end()

else

rs.addnew
rs( "name ")=request.form( "name ")
rs( "sex ")=request.form( "sex ")
rs( "sfzid ")=request.form( "sfzid ")
rs( "tel ")=request.form( "tel ")
rs( "adslid ")=request.form( "adslid ")
rs( "tcyid ")=request.form( "tcyid ")
rs.update
end if

rs.close