在delphi中取存储过程的返回值
2009-11-28 15:48
267 查看
在delphi中取存储过程的返回值
Close;
SQL.Clear;
SQL.Text:='declare @ReturnCount int exec Pr_SelStockHead '''+StockNo+''',@ReturnCount output select @ReturnCount';
open;
CountNO:=fields[0].value;
cxtxtdtNameCSHYH.Text:=IntToStr(CountNO);
在sql语句里面 如果有返回值的话,可以是用return 返回,,其他的都是参数返回,如果取参数的话 从 Parameters[1].Value 开始,如果取return 的返回值 要用Parameters[0].Value
调用存储过程的方法,用adodataset控件
function TfrmPower_Cut.HasNewPowerCutInfo: Boolean;
begin
Result := False;
with spPower_Cut do //spPower_Cut为Tadostoredproc控件
begin
Close;
ProcedureName := 'p_Has_PowerCut_Info';
with Parameters do
begin
Clear;
Refresh;
ParamByName('@BiggestID').Direction
:= pdInputOutput;
ParamByName('@BiggestID').Value
:= FPower_Cut_ID_Refresh;
ParamByName('@NoProcess').Direction
:= pdInputOutput;
ParamByName('@NoProcess').Value
:= FNoProcess;
ParamByName('@IsPassTimeAndNoProc').Direction
:= pdInputOutput;
ParamByName('@IsPassTimeAndNoProc').Value
:= FIsPassTimeAndNoProc;
ParamByName('@IsNearestTime').Direction
:= pdInputOutput;
ParamByName('@IsNearestTime').Value
:= FIsNearestTime;
ParamByName('@IsDelete').Direction
:= pdInputOutput;
ParamByName('@IsDelete').Value
:= FIsNearestTime;
ParamByName('@Hour').Value
:= 3;
end;
Prepared;
try
ExecProc;
if Parameters[0].Value <> FPower_Cut_ID_Refresh then
begin
FPower_Cut_ID_Refresh := Parameters[1].Value;
Result := True;
end;
if Parameters[2].Value <> FNoProcess then
begin
FNoProcess := Parameters[2].Value;
Result := True;
end;
if Parameters[3].Value <> FIsPassTimeAndNoProc then
begin
FIsPassTimeAndNoProc := Parameters[3].Value;
Result := True;
end;
if Parameters[4].Value <> FIsNearestTime then
begin
FIsNearestTime := Parameters[4].Value;
Result := True;
end;
if Parameters[5].Value <> FIsDelete then
begin
FIsDelete := Parameters[5].Value;
Result := True;
end;
except
on e: Exception do
ShowMessage(e.Message);
end;
end;
end;
存储过程
/*
功能: 判断数据库内是否有新的呼叫中心停电信息
参数: @BiggestID 客户端最大的记录ID,如果小于当前表中的ID,则返回最大的ID,客户端据此判断是否刷新
返回值: 无
*/
ALTER procedure p_Has_PowerCut_Info @BiggestID bigint=0 output, @NoProcess int=0 output,
@IsPassTimeAndNoProc int=0 output, @IsNearestTime int=0 output, @IsDelete int=0 output, @Hour int=3 as
begin
declare @tmp_ID bigint,@tmp_NoProcess int
select @tmp_ID=Power_Cut_ID from Power_Cut
if (@@error=0) and (@@rowcount>0)
if @tmp_id>@BiggestID
set @BiggestID=@tmp_ID
select @tmp_NoProcess=count(*) from Power_Cut where PC_ProcType=0
if (@@error=0) and (@@rowcount>0)
set @NoProcess=@tmp_NoProcess
--超过发送时间未处理
select @IsPassTimeAndNoProc=count(case when (getdate()>PC_StartTime and PC_ProcType=0) then 1 end) from Power_Cut
--距离发送时间还有3小时未处理
select @IsNearestTime=count(case when (DATEDIFF(minute, getdate(),
PC_StartTime)>=0 and DATEDIFF(minute, getdate(),
PC_StartTime)<@Hour*60
and PC_ProcType=0) then 1 end) from Power_Cut
select @IsDelete=count(*) from Power_Cut where PC_State=2
return @BiggestID
end
return 返回的是正确或错误的标志,比如 100: 成功 0: 失败(未知原因) 1: 参数错误 2: .... 然后参数里面返回具体需要的数据
Close;
SQL.Clear;
SQL.Text:='declare @ReturnCount int exec Pr_SelStockHead '''+StockNo+''',@ReturnCount output select @ReturnCount';
open;
CountNO:=fields[0].value;
cxtxtdtNameCSHYH.Text:=IntToStr(CountNO);
在sql语句里面 如果有返回值的话,可以是用return 返回,,其他的都是参数返回,如果取参数的话 从 Parameters[1].Value 开始,如果取return 的返回值 要用Parameters[0].Value
调用存储过程的方法,用adodataset控件
function TfrmPower_Cut.HasNewPowerCutInfo: Boolean;
begin
Result := False;
with spPower_Cut do //spPower_Cut为Tadostoredproc控件
begin
Close;
ProcedureName := 'p_Has_PowerCut_Info';
with Parameters do
begin
Clear;
Refresh;
ParamByName('@BiggestID').Direction
:= pdInputOutput;
ParamByName('@BiggestID').Value
:= FPower_Cut_ID_Refresh;
ParamByName('@NoProcess').Direction
:= pdInputOutput;
ParamByName('@NoProcess').Value
:= FNoProcess;
ParamByName('@IsPassTimeAndNoProc').Direction
:= pdInputOutput;
ParamByName('@IsPassTimeAndNoProc').Value
:= FIsPassTimeAndNoProc;
ParamByName('@IsNearestTime').Direction
:= pdInputOutput;
ParamByName('@IsNearestTime').Value
:= FIsNearestTime;
ParamByName('@IsDelete').Direction
:= pdInputOutput;
ParamByName('@IsDelete').Value
:= FIsNearestTime;
ParamByName('@Hour').Value
:= 3;
end;
Prepared;
try
ExecProc;
if Parameters[0].Value <> FPower_Cut_ID_Refresh then
begin
FPower_Cut_ID_Refresh := Parameters[1].Value;
Result := True;
end;
if Parameters[2].Value <> FNoProcess then
begin
FNoProcess := Parameters[2].Value;
Result := True;
end;
if Parameters[3].Value <> FIsPassTimeAndNoProc then
begin
FIsPassTimeAndNoProc := Parameters[3].Value;
Result := True;
end;
if Parameters[4].Value <> FIsNearestTime then
begin
FIsNearestTime := Parameters[4].Value;
Result := True;
end;
if Parameters[5].Value <> FIsDelete then
begin
FIsDelete := Parameters[5].Value;
Result := True;
end;
except
on e: Exception do
ShowMessage(e.Message);
end;
end;
end;
存储过程
/*
功能: 判断数据库内是否有新的呼叫中心停电信息
参数: @BiggestID 客户端最大的记录ID,如果小于当前表中的ID,则返回最大的ID,客户端据此判断是否刷新
返回值: 无
*/
ALTER procedure p_Has_PowerCut_Info @BiggestID bigint=0 output, @NoProcess int=0 output,
@IsPassTimeAndNoProc int=0 output, @IsNearestTime int=0 output, @IsDelete int=0 output, @Hour int=3 as
begin
declare @tmp_ID bigint,@tmp_NoProcess int
select @tmp_ID=Power_Cut_ID from Power_Cut
if (@@error=0) and (@@rowcount>0)
if @tmp_id>@BiggestID
set @BiggestID=@tmp_ID
select @tmp_NoProcess=count(*) from Power_Cut where PC_ProcType=0
if (@@error=0) and (@@rowcount>0)
set @NoProcess=@tmp_NoProcess
--超过发送时间未处理
select @IsPassTimeAndNoProc=count(case when (getdate()>PC_StartTime and PC_ProcType=0) then 1 end) from Power_Cut
--距离发送时间还有3小时未处理
select @IsNearestTime=count(case when (DATEDIFF(minute, getdate(),
PC_StartTime)>=0 and DATEDIFF(minute, getdate(),
PC_StartTime)<@Hour*60
and PC_ProcType=0) then 1 end) from Power_Cut
select @IsDelete=count(*) from Power_Cut where PC_State=2
return @BiggestID
end
return 返回的是正确或错误的标志,比如 100: 成功 0: 失败(未知原因) 1: 参数错误 2: .... 然后参数里面返回具体需要的数据
相关文章推荐
- Delphi下调用有返回值的存储过程
- delphi中调用oracle的存储过程(ADODataSet,ADOQuery,过程带返回值不带返回值均有)
- 编写将表名和字段名作为参数并带返回值的存储过程
- 存储过程-返回值
- SQL SERVER有返回值的存储过程的使用
- 存储过程中的output输出参数及return返回值参数问题
- 将java的集合转换为数据库集合类型 解决weblogic调用存储过程的时候,返回值乱码问题
- C#获取存储过程的Return返回值和Output输出参数值
- 存储过程带事务,拼接id,返回值
- Delphi写Sql2000扩展存储过程的例子
- mysql 调用带返回值的存储过程
- (转载)delphi 中如何调用sql 存储过程
- ASP.NET 调用带有返回值的存储过程及获取其返回值
- sqlserver数据库中有参数有返回值的存储过程
- 如何在PB脚本当中获取存储过程的返回值(翻译)
- 如何在Delphi中调用oracle的存储过程返回数据集
- C#.net获取存储过程的Return返回值和Output输出参数值
- 在C#中调用存储过程中的两种返回值
- 存储过程共有三种返回值
- C语言调用存储过程并且获得返回值