示例存储过程:
create procedure proc_loginusername varchar(20),password varchar(20)asdeclare @result intselect @result=count(*) from loginuser where user=@username and pass=@passwordif @result=0return 0return 1goDelphi代码:var ret:integer;...... with ADOStoredProc1 do begin Close; ProcedureName:='proc_login'; Parameters.Clear; Parameters.Refresh; Parameters.ParamByName('@username').Value:= Edit1.text; Parameters.ParamByName('@password').Value:= Edit2.text; ExecProc; ret:= Parameters.ParamByName('@return_value').Value; end; if ret=1 //用户名密码匹配 begin //你想要的操作 end示例二
在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;beginResult := 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 asbegindeclare @tmp_ID bigint,@tmp_NoProcess intselect @tmp_ID=Power_Cut_ID from Power_Cut if (@@error=0) and (@@rowcount>0) if @tmp_id>@BiggestID set @BiggestID=@tmp_IDselect @tmp_NoProcess=count(*) from Power_Cut where PC_ProcType=0if (@@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_Cutselect @IsDelete=count(*) from Power_Cut where PC_State=2return @BiggestIDendreturn 返回的是正确或错误的标志,比如 100: 成功 0: 失败(未知原因) 1: 参数错误 2: .... 然后参数里面返回具体需要的数据