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

数据库不插入重复值
ID=Request.Form( "ID ")
  if    
 
set   Conn=Server.CreateObject( "ADODB.Connection ")
Conn.open   Application( "DSN ")
'on   error   resume   next
  ID=replace(Request.Form( "ID "), " ' ", " ' ' ")
CLIENT_ID=request.form( "CLIENT_ID ")

sql4= "insert   into   tblJob(ID,CLIENT_ID)   values( ' "&ID& " ', ' "&CLIENT_ID& " ') "  

conn.execute   sql4
我if语句怎么写可以实现,使ID值插入数据库不重复,
例如:我数据库中有了123,当我再插123时数据库不插入此条记录

------解决方案--------------------
sql= "select * from table where id= ' "&id& " ' "
rs.open sql,conn,1,1
if not rs.eof then
'输出提示id已存在
else
'写入数据库
sql4= "insert into tblJob(ID,CLIENT_ID) values( ' "&ID& " ', ' "&CLIENT_ID& " ') "
conn.execute sql4
end if
rs.close

------解决方案--------------------
rs1
selec max(id)+1 as xx ...........
rs( "ID ")=rs1( "id ")
........
------解决方案--------------------
就算是任意的也不要紧, 以年月日时分秒毫秒取得一个值(基本不太有可能再重复了) 然后写入即可.

Function RndID()
.....
End function

insert into (...) values(.. ' " & RndID & " ')