请教!添加或删除记录时可以判断某一条件下某字段的数值不能重复吗?

cool_sky 2004-04-26 10:38:23
表A(access2000)
字段:a,b,c
想实现当添加或修改记录时自动判断表中当a,b字段为某一值时c字段数值是否重复??
如果重复提示重新输入
谢谢
...全文
66 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
charlse168 2004-04-30
  • 打赏
  • 举报
回复
同意天生本王观点, 在VB程序中获取ADO的错误
或者设定一个记录集的约束. 写清楚条件就成
SaySorry 2004-04-30
  • 打赏
  • 举报
回复
把这三个字段设置成联合主键

tjficcbw 2004-04-30
  • 打赏
  • 举报
回复
自愧不如
cool_sky 2004-04-27
  • 打赏
  • 举报
回复
rs.open "select 1 from tableA where a=1 and b=1 and c between 1 and 10 ",cn
rs.open "select * from table where a=1 and b=1 and c >=1 and c <=10 " ,cn

这两句有本质上的区别吗?前一种会不会更快点??
cool_sky 2004-04-26
  • 打赏
  • 举报
回复
谢谢,但如果我要加入或修改的记录是很多条,这样好像不行吧?
比如a=1,b=1,c为一个范围(比如1-10)
那应该怎么办??
谢谢
tjficcbw 2004-04-26
  • 打赏
  • 举报
回复
设va,vb,vc为新记录的三个值。
如果某个值特定再替换,
<%sql="select * from table where a='"& va &"' and b='"& vb &"' and c='"& vc &"'"
rs.Open SQL,adocon,2,3

if rs.eof then
sql="insert into table(a,b,c) values('"& va &"','"& vb &"','"& vc &"')"
rs.Open SQL,adocon,2,3
else
'提示输错
end if
%>
mmcgzs 2004-04-26
  • 打赏
  • 举报
回复
可以实现
yoki 2004-04-26
  • 打赏
  • 举报
回复
rs.open "select 1 from tableA where a=1 and b=1 and c between 1 and 10",cn
if not rs.eof then
msgbox "数据库中已经存在相应记录,请重新输入"
else
cn.execute"insert into tableA........."
end if
cool_sky 2004-04-26
  • 打赏
  • 举报
回复
sql="select * from table where a=1 and b=1 and c>=1 and c<=10"
rs.Open SQL,adocon,2,3

我通过这个判断是否存在,如果没有则在插入或更新记录,
不知道哪种效率高点??
cslf 2004-04-26
  • 打赏
  • 举报
回复
加个while循环就成。
tjficcbw 2004-04-26
  • 打赏
  • 举报
回复
以下程序我经过测试完全成功:(假设a,b,全是字符型的)

<!--#include file="../Connections/myconn.asp" -->
<%
 Set rs = Server.CreateObject("ADODB.Recordset")
for i=1 to 10
sql="select * from A where a='1' and b='1' and c='"& i &"'"
rs.Open SQL,adocon,2,3
if rs.eof then
rs.close
sql="insert into A(a,b,c) values('1','1','"& i &"')"
rs.Open SQL,adocon,2,3
else
rs.close
'提示输错
end if
next
%>
tjficcbw 2004-04-26
  • 打赏
  • 举报
回复
以上没改完就上去了。如下:

<%
for i=1 to 10
sql="select * from table where a=1 and b=1 and c='"& i &"'"
rs.Open SQL,adocon,2,3

if rs.eof then
sql="insert into table(a,b,c) values(1,1,'"& i &"')"
rs.Open SQL,adocon,2,3
else
'提示输错
end if
next
%>
tjficcbw 2004-04-26
  • 打赏
  • 举报
回复
<%
for i=1 to 10
sql="select * from table where a=1 and b=1 and c='"& vc &"'"
rs.Open SQL,adocon,2,3

if rs.eof then
sql="insert into table(a,b,c) values('"& va &"','"& vb &"','"& vc &"')"
rs.Open SQL,adocon,2,3
else
'提示输错
end if
next
%>
cool_sky 2004-04-26
  • 打赏
  • 举报
回复
我想实现比如
a=1,b=1,c为一个范围(如1-10)
这十条记录,添加时自动判断字段c的数值与数据库中a=1,b=2的记录中字段c的数值是否有重复??
ryuginka 2004-04-26
  • 打赏
  • 举报
回复
当然可以啊,你再保存之前进行判断,到数据库中查找,如果满足条件就不能保存,给出提示就行了
flc 2004-04-26
  • 打赏
  • 举报
回复
不明白你什么意思。

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧