Delphi:如何获取存储过程的输出参数的值?

编程入门 行业动态 更新时间:2024-10-24 12:26:41
本文介绍了Delphi:如何获取存储过程的输出参数的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在Delphi中以编程方式创建一个SQLDataSet,并使用它来执行一个存储过程并获取一个输出参数的值。看起来很容易,但我不能让它工作。

I want to programatically create a SQLDataSet in Delphi and use it to execute a Stored Procedure and get the value of an output parameter. Looks easy but I can't make it work.

这是一个在SQL Server中的哑存储过程:

Here is a dumb stored procedure in SQL Server:

CREATE PROCEDURE [dbo].getValue @x INT OUTPUT AS BEGIN SET @x = 10; END

现在这里是我试过的,

Now here is one of the variations that I tried and didn't work:

proc := TSQLDataSet.Create(nil); proc.SQLConnection := DefaultConnection; proc.CommandText := 'getValue'; proc.Params.CreateParam(ftInteger, '@x', ptOutput); proc.Params.ParamByName('@x').Value := 0; proc.ExecSQL(False); value := newIdProc.Params.ParamByName('@x').AsInteger;

我认为这很容易,但有一些注册 错误。

I thought it would be easy, but there are some registred bugs around this issue.

推荐答案

看起来像是设置CommandType和SchemaName,不创建Param:

Looks like it works if you set the CommandType and SchemaName and don't create the Param:

proc := TSQLDataSet.Create(nil); proc.SQLConnection := DefaultConnection; proc.CommandType := ctStoredProc; proc.SchemaName := 'dbo'; proc.CommandText := 'getValue'; proc.ExecSQL(False); value := proc.Params.ParamByName('@x').AsInteger;

更多推荐

Delphi:如何获取存储过程的输出参数的值?

本文发布于:2023-10-28 23:21:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   参数   Delphi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!