SubSonic:检索存储过程OUT参数的值

时间:2022-03-09 16:40:33

I love your tool. I have been using it a lot, but just today I ran into a problem...

我喜欢你的工具。我一直在使用它,但就在今天我遇到了一个问题......

I wrote a stored procedure that returns some values via OUT parameters, but SubSonic does not seem to generate the out parametes of the stored procedure method. For example, for SPI like this:

我写了一个存储过程,通过OUT参数返回一些值,但SubSonic似乎没有生成存储过程方法的out参数。例如,对于这样的SPI:

CREATE PROC dbo.MyProc @param1 int, @param2 int out, @param3 varchar(150) out

It generates signature

它会生成签名

SPs.MyProc(int? param1, int? param2, string param3

I would expect it to generate this

我希望它能产生这个

SPs.MyProc(int? param1, out int? param2, out string param3)

Well, considering that the method actually just configures the SP and does not actually execute it, I woiuld expect Subsonic to generate this

好吧,考虑到该方法实际上只是配置SP并且实际上并没有执行它,我希望Subsonic能够生成这个

SPs.MyProc(int? param1, ref int? param2, ref string param3)

How do you guys solve this problem? Is there something like that in Subsonic already and I just missed it?

你们是如何解决这个问题的?在Subsonic中是否有类似的东西,我只是错过了它?

4 个解决方案

#1


SOURCE You can acess OuPut parametes of SP in SubSonic using StoredProcedure.OutputValues;

来源你可以使用StoredProcedure.OutputValues在SubSonic中获取SP的OuPut参数;

Folowing is the chunk of code to access OutPut parameters of SP, here i have sued SP “UspTestOutPut”:

Folowing是访问SP的OutPut参数的代码块,这里我起诉SP“UspTestOutPut”:

StoredProcedure s = SPs.UspTestOutPut(”10″, “15″);
s.Execute();
s.OutputValues.ForEach(delegate(object objOutput)
{
    Response.Write(”OutPutValues=”+objOutput.ToString());
});

#2


You have to instantiate the SP as an object then run it - it will then hand you the OUTPUT param as a property.

您必须将SP实例化为对象然后运行它 - 然后它将把OUTPUT参数作为属性传递给您。

#3


It seems that the usage of OutputParameters doesn't work in combination with .GetReader(), but only with .Execute().

似乎OutputParameters的使用不能与.GetReader()结合使用,而只能与.Execute()一起使用。

I'm unable to retrieve records from the database in combination with the usage of OUTPUT parameters.

我无法从数据库中检索记录以及OUTPUT参数的使用。

For example, I have a storedprocedure that returns a list of newsletters from the database, but I want to use the paging functionality of SQL Server 2005. So I provide the pageSize and actual page I want to see. In the same procedure I want to count the amount of pages that are available and return that using an output variable.

例如,我有一个storedprocedure,它返回数据库中的新闻简报列表,但我想使用SQL Server 2005的分页功能。所以我提供了我想看的pageSize和实际页面。在同一过程中,我想计算可用的页面数量,并使用输出变量返回该页面。

I don't get it to work. The list with OutputParameters has 1 item in it, but the value is always NULL.

我不懂它。带有OutputParameters的列表中有1个项目,但该值始终为NULL。

#4


I'm using subsonic and Sqlserver 2005 server. for the paging functionality, i pass the currentpage and pagesize as input parameters. To get the total number of records, i use @TotalCount int OUTPUT parameter variable.

我正在使用亚音速和Sqlserver 2005服务器。对于分页功能,我将currentpage和pagesize作为输入参数传递。为了获得记录总数,我使用@TotalCount int OUTPUT参数变量。

in the StoresPrecedure, i use like this:

在StoresPrecedure中,我使用如下:

Select * from TestTable where PageSize=@PageSize and CurrentPage = @CurrentPage -- it gets the current page records.

从TestTable中选择*,其中PageSize = @ PageSize和CurrentPage = @CurrentPage - 它获取当前页面记录。

Set @Query ="Insert ....."

设置@Query =“插入.....”

EXEC sp_executesql @Query

EXEC sp_executesql @Query

SET @TotalCount = @@Rowcount -- total number of records affected by insert statement

SET @TotalCount = @@ Rowcount - 插入语句影响的记录总数

in my C#.net - subsonic class file, i use, GetDataSet() to get the result DataSet and OutputValues[0] to get the value from the output parameter.

在我的C#.net - 亚音类文件中,我使用GetDataSet()来获取结果DataSet和OutputValues [0]以从输出参数中获取值。

      DataSet results = sp.GetDataSet(); // current page records

      int totalCnt = Convert.ToInt32(sp.OutputValues[0].ToString()); // total number of
                                                             //records from outputparameter

#1


SOURCE You can acess OuPut parametes of SP in SubSonic using StoredProcedure.OutputValues;

来源你可以使用StoredProcedure.OutputValues在SubSonic中获取SP的OuPut参数;

Folowing is the chunk of code to access OutPut parameters of SP, here i have sued SP “UspTestOutPut”:

Folowing是访问SP的OutPut参数的代码块,这里我起诉SP“UspTestOutPut”:

StoredProcedure s = SPs.UspTestOutPut(”10″, “15″);
s.Execute();
s.OutputValues.ForEach(delegate(object objOutput)
{
    Response.Write(”OutPutValues=”+objOutput.ToString());
});

#2


You have to instantiate the SP as an object then run it - it will then hand you the OUTPUT param as a property.

您必须将SP实例化为对象然后运行它 - 然后它将把OUTPUT参数作为属性传递给您。

#3


It seems that the usage of OutputParameters doesn't work in combination with .GetReader(), but only with .Execute().

似乎OutputParameters的使用不能与.GetReader()结合使用,而只能与.Execute()一起使用。

I'm unable to retrieve records from the database in combination with the usage of OUTPUT parameters.

我无法从数据库中检索记录以及OUTPUT参数的使用。

For example, I have a storedprocedure that returns a list of newsletters from the database, but I want to use the paging functionality of SQL Server 2005. So I provide the pageSize and actual page I want to see. In the same procedure I want to count the amount of pages that are available and return that using an output variable.

例如,我有一个storedprocedure,它返回数据库中的新闻简报列表,但我想使用SQL Server 2005的分页功能。所以我提供了我想看的pageSize和实际页面。在同一过程中,我想计算可用的页面数量,并使用输出变量返回该页面。

I don't get it to work. The list with OutputParameters has 1 item in it, but the value is always NULL.

我不懂它。带有OutputParameters的列表中有1个项目,但该值始终为NULL。

#4


I'm using subsonic and Sqlserver 2005 server. for the paging functionality, i pass the currentpage and pagesize as input parameters. To get the total number of records, i use @TotalCount int OUTPUT parameter variable.

我正在使用亚音速和Sqlserver 2005服务器。对于分页功能,我将currentpage和pagesize作为输入参数传递。为了获得记录总数,我使用@TotalCount int OUTPUT参数变量。

in the StoresPrecedure, i use like this:

在StoresPrecedure中,我使用如下:

Select * from TestTable where PageSize=@PageSize and CurrentPage = @CurrentPage -- it gets the current page records.

从TestTable中选择*,其中PageSize = @ PageSize和CurrentPage = @CurrentPage - 它获取当前页面记录。

Set @Query ="Insert ....."

设置@Query =“插入.....”

EXEC sp_executesql @Query

EXEC sp_executesql @Query

SET @TotalCount = @@Rowcount -- total number of records affected by insert statement

SET @TotalCount = @@ Rowcount - 插入语句影响的记录总数

in my C#.net - subsonic class file, i use, GetDataSet() to get the result DataSet and OutputValues[0] to get the value from the output parameter.

在我的C#.net - 亚音类文件中,我使用GetDataSet()来获取结果DataSet和OutputValues [0]以从输出参数中获取值。

      DataSet results = sp.GetDataSet(); // current page records

      int totalCnt = Convert.ToInt32(sp.OutputValues[0].ToString()); // total number of
                                                             //records from outputparameter