存储过程:
CREATE procedure usp_xyx_select_update_where
(@sale_date datetime,@sale_man char(20),@sale_to char(20),
@sale_ticket_number int,@sale_ticket_number_hs int output,
@errcode smallint output)
as
select @ErrCode=0
select @sale_ticket_number_hs=0
select @sale_ticket_number_hs=ticket_num from eg_sale_hs_number where sale_to =@sale_to
if (@sale_ticket_number_hs- @sale_ticket_number<0)
begin
select @ErrCode=1
return @ErrCode
end
else
begin
update eg_sale_hs_number set ticket_num=@sale_ticket_number_hs- @sale_ticket_number
where sale_to =@sale_to
insert into eg_sale_plane(sale_date,sale_man,sale_to,sale_ticket_number)
values(@sale_date,@sale_man,@sale_to,@sale_ticket_number)
select * from eg_sale_plane
select @sale_ticket_number_hs=@sale_ticket_number_hs- @sale_ticket_number
select @ErrCode=0
return @ErrCode
end
应用服务器端:
function ttest_updates.update_st(sale_date:tdatetime;sale_man:string;sale_to:string;sale_ticket_number:integer):smallint;
begin
storedproc1.Close;
storedproc1.ParamByName('@sale_date').asdate:=sale_date;
storedproc1.ParamByName('@sale_man').asstring:=sale_man;
storedproc1.ParamByName('@sale_to').asstring:=sale_to;
storedproc1.ParamByName('@sale_ticket_number').asinteger:=sale_ticket_number;
storedproc1.ExecProc;
result:=storedProc1.ParamByName('@errcode').value;
end;
客户端:
procedure TForm2.BitBtn1Click(Sender: TObject);
var
errcode:smallint;
sale_date:tdatetime;
sale_man,sale_to:string;
sale_ticket_number:integer;
v:variant;
begin
if strtoint(edit4.text)>strtoint(dbedit1.Text) then
begin
application.MessageBox('对不起,机票已没有这么多了','提示',0);
exit;
end;
button1.Enabled :=true;
button2.Enabled :=true;
bitbtn1.Enabled :=false;
bitbtn2.Enabled :=false;
v:=dcomconnection1.GetServer;
sale_date:=strtodate(edit1.text);
sale_man:=edit2.text ;
sale_to:=combobox1.text ;
sale_ticket_number:=strtoint(edit4.text);
v:=dcomconnection1.AppServer.update_st(sale_date,sale_man,sale_to,sale_ticket_number);