标题:添加记录又出错了.我疯了
只看楼主
missking
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-4-8
 问题点数:0 回复次数:0 
添加记录又出错了.我疯了
我郁闷又出错了.
错误信息:
---------------------------
Debugger Exception Notification
---------------------------
Project AppName.exe raised exception class EOleException with message '违反了 PRIMARY KEY 约束 'PK_BookStateInfo'。不能在对象 'BookStateInfo' 中插入重复键。'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

create proc Insert_BookStateInfo
@ISDN varchar(10),
@TotalStock integer
as
declare @State varchar(10),@BookID varchar(14),@i integer,@tempBookID varchar(3)
set @i=0
set @State='归还'
while (@TotalStock>@i)
begin
set @tempBookID=(convert(varchar(3),(select isnull(max(convert(int,right(BookID,len(BookID)-10))),0)+1
from BookStateInfo
where ISDN=@ISDN )) )
while (len(@tempBookID)<3)
set @tempBookID='0'+@tempBookID
set @BookID=@ISDN+'-'+@tempBookID
insert into BookStateInfo(ISDN,BookID,State)
values(@ISDN,@BookID,@State)
set @i=@i+1
end
update BookInfo
set TotalStock=isnull(TotalStock,0)+@TotalStock
from BookInfo as a ,BookStateInfo as b
where a.ISDN=b.ISDN and b.ISDN=@ISDN
update BookInfo
set BookStock=isnull(BookStock,0)+@TotalStock
from BookInfo as a ,BookStateInfo as b
where a.ISDN=b.ISDN and b.ISDN=@ISDN
搜索更多相关主题的帖子: 记录 
2006-04-20 09:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-58715-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.121938 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved