示例存储过程:
create procedure proc_login
username varchar(20),
password varchar(20)
as
declare @result int
select @result=count(*) from loginuser where user=@username and pass=@password
if @result=0
return 0
return 1
go

Delphi代码:
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;
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中如何获得SQL中存储过程的返回值?的更多相关文章

  1. C#中的函数(二) 有参有返回值的函数

    接上一篇 C#中的函数(-) 无参无返回值的函数 http://www.cnblogs.com/fzxiaoyi/p/8502613.html 这次研究下C#中的函数(二) 有参有返回值的函数 依然写 ...

  2. SqlServer如何获取存储过程的返回值

    1.Output参数返回值 1 CREATE PROCEDURE [dbo].[upInformation]( 2 @age int , 3 @id bigint OUTPUT 4 ) 5 AS 6 ...

  3. 利用SQLServer查询分析器获取存储过程的返回值,检查测试存储过程

    1.存储过程没有返回值的情况(即存储过程语句中没有return之类的语句)用方法 int count = ExecuteNonQuery(..)执行存储过程其返回值只有两种情况(1)如果通过查询分析器 ...

  4. .net 接收存储过程的返回值 。。。。

    .net 接收存储过程的返回值 .... Posted on 2009-06-10 20:26 且行且思 阅读(...) 评论(...) 编辑 收藏 例如在向数据库添加新数据时,需要检测是否有重复 本 ...

  5. 关于ExecuteNonQuery执行存储过程的返回值 、、实例讲解存储过程的返回值与传出参数、、、C#获取存储过程的 Return返回值和Output输出参数值

    关于ExecuteNonQuery执行存储过程的返回值 用到过ExecuteNonQuery()函数的朋友们在开发的时候肯定这么用过. if(cmd.ExecuteNonQuery("xxx ...

  6. C#获取执行存储过程的" 返回值"代码

    以下是C#代码: /// <summary> /// 执行存储过程,返回" 返回值" /// </summary> /// <param name=& ...

  7. 用sp_executesql执行动态SQL语句及获得返回值

    过去我执行拼凑出来的动态SQL语句,都直接使用EXEC @sql 的方式.有好几次,都看到有资料说,应该尽量使用 sp_executesql. 究其原因,是因为仅仅参数不同的情况下,sp_execut ...

  8. Entity Framework中对存储过程的返回值的处理

    很早就开始注意到EF了,但一直没有机会用,换了工作后,第一个项目就使用EF6进行开发. 项目不是很大,EF完全可以胜任. 但是开发过程中,难免还是会遇到一些复杂的运算,需要频繁访问数据库. 此时,想到 ...

  9. C#EF中,使用类似于SQL中的% 模糊查询

    最近在做项目的时候需要使用到模糊查询,但是后台使用EF写的 而不是ADO或者是Dapper,如果是这样的话,我们就可以使用Sql语句直接进行模糊查询 现在我们需要在LINQ中使用类似于模糊查询 在EF ...

随机推荐

  1. 【数据结构】循环链表&&双向链表详解和代码实例

    喜欢的话可以扫码关注我们的公众号哦,更多精彩尽在微信公众号[程序猿声] 01 循环链表 1.1 什么是循环链表? 前面介绍了单链表,相信大家还记得相关的概念.其实循环链表跟单链表也没有差别很多,只是在 ...

  2. 03以太网帧结构(链路层 IEEE802.3)

    OSI七层模型:从底往上记(研究细致时用) 物理层:单位bit,字节byte,同轴电缆,光纤,二进制,比特流 数据链路层:帧,16进制,0-9,A-FMac地址->全网唯一性     mac地址 ...

  3. 记录:C#监视某个文件的打开记录

    首先,先说下为什么要搞这个: 1.首先,我的电脑里有5万左右的目录或文件,用于存放歌曲,数量众多.2.我不一定会用哪种软件听歌(不过也就是几种而已).3.我想在听歌的时候,检测哪首首歌被打开,能获取到 ...

  4. 北京Uber优步司机奖励政策(3月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. CF 914 D. Bash and a Tough Math Puzzle

    D. Bash and a Tough Math Puzzle http://codeforces.com/contest/914/problem/D 题意: 单点修改,每次询问一段l~r区间能否去掉 ...

  6. 1030: [JSOI2007]文本生成器

    1030: [JSOI2007]文本生成器 https://www.lydsy.com/JudgeOnline/problem.php?id=1030 分析: AC自动机+dp. 正难则反,求满足的, ...

  7. Spring的定时任务(任务调度)<task:scheduled-tasks>

    Spring内部有一个task是Spring自带的一个设定时间自动任务调度,提供了两种方式进行配置,一种是注解的方式,而另外一种就是XML配置方式了.注解方式比较简洁,XML配置方式相对而言有些繁琐, ...

  8. python 函数定义顺序

    #!/usr/bin/python # Hello World def order(): print("haha") print('Hello World!') order()

  9. java对于Redis中jedis的操作

    package com.answer.redis; import java.util.HashMap; import java.util.List; import java.util.Map; imp ...

  10. uvaoj1225Digit Counting(暴力)

    Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequen ...