添加记录又出错了.我疯了
我郁闷又出错了.错误信息:
---------------------------
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