关于插入记录前如何判断数据已经存在了呢?
现在要向表里插入一条记录,如果其中一个字段有重名的话,就不插入,我是这样写的..
<%
account=trim(request.form( "account "))
pwd=trim(request.form( "pwd "))
truename=trim(request.form( "truename "))
level=trim(request.form( "level "))
set rs=server.CreateObject( "ADODB.RecordSet ")
sql= "select * from user where username= ' "&account& " ' "
rs.open sql,conndb,3,2
if rs.eof or rs.bof then //不存在记录的话,就插入
rs.addnew
rs( "username ")=account
rs( "userpwd ")=md5(pwd)
rs( "truename ")=truename
rs( "level ")=level
rs.update
end if
rs.close
set rs=nothing
closedb
response.redirect "admin.asp "
%>
如果插入记录时,传递的account是数字的话,这个明显就不行,那就得换成
"select * from user where username= "&account& " "
不管account是数字还是字符串,都直接用一条来SQL怎么来搞定?
------解决方案--------------------先做一个转化
account=cstr(trim(request.form( "account ")))
然后就可以用这句了
sql= "select * from user where username= ' "&account& " ' "