存储过程
CREATE PROCEDURE tcc_lsctime(@edit2 char(12) ) AS
begin
if not exists( select * from lscw where cpid = @edit2) and @edit2!=''
insert into lscw(cpid,ctime) values(@edit2,getdate())
end
GO
delphi代码
begin
unit2.DataModule2.ADOStoredProc1.Close;
unit2.DataModule2.ADOStoredProc1.ProcedureName := 'tcc_lsctime';
unit2.DataModule2.ADOStoredProc1.Parameters.Clear;
unit2.DataModule2.ADOStoredProc1.Parameters.CreateParameter('@edit2',ftString,pdInput,12,edit2.Text);
//unit2.DataModule2.ADOStoredProc1.Parameters.ParamByName('@edit2').Value:=edit2.Text;
unit2.DataModule2.ADOStoredProc1.Prepared:=true;
unit2.DataModule2.ADOStoredProc1.ExecProc;
if edit2.Text='' then
begin
showmessage('车牌号码为空,请重新输入');
exit;
end ;
if 这里需要添加条件,如果存储过程中添加了记录 then
begin
exit;
showmessage('输入成功');
unit4.Form4.Close;
end;
if 这里添加条件,如果存储过程没有添加记录 then
begin
showmessage('重复输入,错误');
unit4.Form4.edit2.Clear;end;
CREATE PROCEDURE tcc_lsctime(@edit2 char(12) ) AS
begin
if not exists( select * from lscw where cpid = @edit2) and @edit2!=''
insert into lscw(cpid,ctime) values(@edit2,getdate())
end
GO
delphi代码
begin
unit2.DataModule2.ADOStoredProc1.Close;
unit2.DataModule2.ADOStoredProc1.ProcedureName := 'tcc_lsctime';
unit2.DataModule2.ADOStoredProc1.Parameters.Clear;
unit2.DataModule2.ADOStoredProc1.Parameters.CreateParameter('@edit2',ftString,pdInput,12,edit2.Text);
//unit2.DataModule2.ADOStoredProc1.Parameters.ParamByName('@edit2').Value:=edit2.Text;
unit2.DataModule2.ADOStoredProc1.Prepared:=true;
unit2.DataModule2.ADOStoredProc1.ExecProc;
if edit2.Text='' then
begin
showmessage('车牌号码为空,请重新输入');
exit;
end ;
if 这里需要添加条件,如果存储过程中添加了记录 then
begin
exit;
showmessage('输入成功');
unit4.Form4.Close;
end;
if 这里添加条件,如果存储过程没有添加记录 then
begin
showmessage('重复输入,错误');
unit4.Form4.edit2.Clear;end;
CREATE PROCEDURE tcc_lsctime(@edit2 char(12) @flag int output ) AS
begin
if not exists( select * from lscw where cpid = @edit2) and @edit2!=''
insert into lscw(cpid,ctime) values(@edit2,getdate()) if @@rowcount >0
begin
set @flag = 1
end
else
begin
set @flag = 0
endend 在代码里也加入这个参数,并指定这个参数的方向为输出:begin
unit2.DataModule2.ADOStoredProc1.Close;
unit2.DataModule2.ADOStoredProc1.ProcedureName := 'tcc_lsctime';
unit2.DataModule2.ADOStoredProc1.Parameters.Clear;
unit2.DataModule2.ADOStoredProc1.Parameters.CreateParameter('@edit2',ftString,pdInput,12,edit2.Text);
//unit2.DataModule2.ADOStoredProc1.Parameters.ParamByName('@edit2').Value:=edit2.Text; 把下面这一行改为输出参数,具体用delphi语法
unit2.DataModule2.ADOStoredProc1.Parameters.CreateParameter('@flag',***********); unit2.DataModule2.ADOStoredProc1.Prepared:=true;
unit2.DataModule2.ADOStoredProc1.ExecProc;
if edit2.Text='' then
begin
showmessage('车牌号码为空,请重新输入');
exit;
end ; 在这里判断存储过程的输出参数if 这里需要添加条件,如果存储过程中添加了记录 then
begin
exit;
showmessage('输入成功');
unit4.Form4.Close;
end;
if 这里添加条件,如果存储过程没有添加记录 then
begin
showmessage('重复输入,错误');
unit4.Form4.edit2.Clear; end;
CREATE PROCEDURE tcc_lsctime(@edit2 char(12) )
AS
set nocount onif not exists( select * from lscw where cpid = @edit2) and @edit2<>''
Begin
insert into lscw(cpid,ctime) values(@edit2,getdate())
if @@rowcount=0
Begin
select 'Fail' as Result,'数据插入未成功' as Message
Return
End
end
select 'Pass' as Result,'数据插入成功' as Message你用程序获取这个记录集,再对记录集的Result做判断不就可以了吗?
我添加了一个,EDIT3,没有返回值。
应该是DELPHI语法的问题。
我在学习学习本人才开始学习,还请大哥们见谅Result不会啊。。我也是想在存储过程中就判断了,然后在DELPHI中显示判断结果的内容。可是不知道该怎么写。
不过我觉着获取记录集的原理应该是一样的吧?
你获取一个记录集,然后判断记录集的字段啊。