
怎么判断添加到数据库的信息重复 VB
用的是dadagrid和adodc输入的信息已经在数据库中存在了,怎么判断添加到数据库的信息与数据库中的信息重复希望用代码...
用的是dadagrid和adodc
输入的信息已经在数据库中存在了,怎么判断添加到数据库的信息与数据库中的信息重复
希望用代码 展开
输入的信息已经在数据库中存在了,怎么判断添加到数据库的信息与数据库中的信息重复
希望用代码 展开
3个回答
展开全部
只能告诉你一个思路,首先看你的库表有没有索引或主键,如果有,按主键或索引select出若干字段,与你要添加的信息的对应字段进行比较,两者不同时insert,如果没有只能按一定条件取出字段比较。
取数据时用distinct子句做唯一筛选
准确来说,如果你的库表本身有唯一索引,是不可能重复插入数据的
取数据时用distinct子句做唯一筛选
准确来说,如果你的库表本身有唯一索引,是不可能重复插入数据的
展开全部
具体的情况具体使用,下面是一个我用过的实例,筛选数据库中的手机号码,列出不重复的,有效的手机号码!
<%
serverD="127.0.0.1"
databaseD="sinocp"
uidD="sa"
pwdD="admin"
connstr="provider=sqloledb;server="&serverD&";database="&databaseD&";uid="&uidD&";pwd="&pwdD&""
set conn=server.createobject("adodb.connection")
conn.open connstr
set rs = Server.CreateObject("ADODB.Recordset")
sql="select distinct tel from project3"
' order by indate desc where 10000<zjbh and zjbh<20000
rs.open sql,conn,1,1
' sql语句中 distinct 字段名 表示过滤这个字段中重复的记录
a = "-"
b = "("
c = "("
d = "0"
e = "13"
f ="—"
g ="*"
q = "#"
w="+"
r=","
t="X"
y="13555555555 "
u="13333333333"
i="13800000000"
o="13500000000"
p="13000000000"
s="13988888888"
h="13900000000"
j="13813888888"
k="13999999999"
l="13900000000"
z="13988888888"
x="*"
v="13555555555"
n="13111111111"
m="13800138000"
qq="13588888888"
ww="13300000000"
ee="13855555555"
rr="13311111111"
tt="."
yy="13888888888"
%>
</head>
<body>
<table width="100%">
<% while not rs.eof
If instr(rs("tel"),a)=0 and instr(rs("tel"),b)=0 and instr(rs("tel"),c)=0 and instr(rs("tel"),d)=0 and len(rs("tel"))=11 and instr(rs("tel"),e)=1 and instr(rs("tel"),f)=0 and instr(rs("tel"),g)=0 and instr(rs("tel"),q)=0 and instr(rs("tel"),w)=0 and instr(rs("tel"),r)=0 and instr(rs("tel"),t)=0 and instr(rs("tel"),y)=0 and instr(rs("tel"),u)=0 and instr(rs("tel"),i)=0 and instr(rs("tel"),o)=0 and instr(rs("tel"),p)=0 and instr(rs("tel"),j)=0 and instr(rs("tel"),h)=0 and instr(rs("tel"),l)=0 and instr(rs("tel"),k)=0 and instr(rs("tel"),z)=0 and instr(rs("tel"),x)=0 and instr(rs("tel"),v)=0 and instr(rs("tel"),n)=0 and instr(rs("tel"),m)=0 and instr(rs("tel"),qq)=0 and instr(rs("tel"),ww)=0 and instr(rs("tel"),ee)=0 and instr(rs("tel"),rr)=0 and instr(rs("tel"),tt)=0 and instr(rs("tel"),yy)=0 Then %>
<tr>
<td><%= rs("tel") %></td>
</tr>
<%
End If
rs.movenext
wend %>
</table>
</body>
</html>
<%
serverD="127.0.0.1"
databaseD="sinocp"
uidD="sa"
pwdD="admin"
connstr="provider=sqloledb;server="&serverD&";database="&databaseD&";uid="&uidD&";pwd="&pwdD&""
set conn=server.createobject("adodb.connection")
conn.open connstr
set rs = Server.CreateObject("ADODB.Recordset")
sql="select distinct tel from project3"
' order by indate desc where 10000<zjbh and zjbh<20000
rs.open sql,conn,1,1
' sql语句中 distinct 字段名 表示过滤这个字段中重复的记录
a = "-"
b = "("
c = "("
d = "0"
e = "13"
f ="—"
g ="*"
q = "#"
w="+"
r=","
t="X"
y="13555555555 "
u="13333333333"
i="13800000000"
o="13500000000"
p="13000000000"
s="13988888888"
h="13900000000"
j="13813888888"
k="13999999999"
l="13900000000"
z="13988888888"
x="*"
v="13555555555"
n="13111111111"
m="13800138000"
qq="13588888888"
ww="13300000000"
ee="13855555555"
rr="13311111111"
tt="."
yy="13888888888"
%>
</head>
<body>
<table width="100%">
<% while not rs.eof
If instr(rs("tel"),a)=0 and instr(rs("tel"),b)=0 and instr(rs("tel"),c)=0 and instr(rs("tel"),d)=0 and len(rs("tel"))=11 and instr(rs("tel"),e)=1 and instr(rs("tel"),f)=0 and instr(rs("tel"),g)=0 and instr(rs("tel"),q)=0 and instr(rs("tel"),w)=0 and instr(rs("tel"),r)=0 and instr(rs("tel"),t)=0 and instr(rs("tel"),y)=0 and instr(rs("tel"),u)=0 and instr(rs("tel"),i)=0 and instr(rs("tel"),o)=0 and instr(rs("tel"),p)=0 and instr(rs("tel"),j)=0 and instr(rs("tel"),h)=0 and instr(rs("tel"),l)=0 and instr(rs("tel"),k)=0 and instr(rs("tel"),z)=0 and instr(rs("tel"),x)=0 and instr(rs("tel"),v)=0 and instr(rs("tel"),n)=0 and instr(rs("tel"),m)=0 and instr(rs("tel"),qq)=0 and instr(rs("tel"),ww)=0 and instr(rs("tel"),ee)=0 and instr(rs("tel"),rr)=0 and instr(rs("tel"),tt)=0 and instr(rs("tel"),yy)=0 Then %>
<tr>
<td><%= rs("tel") %></td>
</tr>
<%
End If
rs.movenext
wend %>
</table>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我很久以前的做法是,首先设置那个字段为'键',然后直接往数据库里输入,如果是重复的,数据库引擎会传回一个错代号,就知道是重复了,再告诉用户.
后来就再没机会写数据库程序,现在也忘光了:(
后来就再没机会写数据库程序,现在也忘光了:(
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询