繁体   English   中英

从EF4调用存储过程时返回值的问题

[英]Issue with return Value when calling stored procedure from EF4

我在SQL Server 2008中编写了以下存储过程:

ALTER Procedure [dbo].[usp_TodayNumberOfRegisteration] 
(
@TodayShamsiDate nvarchar
)
AS
Select COUNT(csci.Id) as cc1  FROM dbo.Complex_Service_Cart_Items csci INNER JOIN dbo.Complex_Service_Cart csc
ON csci.Id_Complex_Service_Cart=csc.Id
WHERE (csci.Id_Complex_Service='2cca1a67-34f4-4837-bebe-f3ba4c72b98d' or csci.Id_Complex_Service='8430cad2-dbb1-4425-bb8b-a7e158f688c4') 
and csc.TFIsPaymentComplete=1 
and csc.TFDateBackFromBankp= RTRIM( @TodayShamsiDate)

我通过这种方式通过EF4从C#codebehind调用它:

string shamsiDate = Date.getShamsiDate();
returnValue = Convert.ToString(db.getTodayNumberOfRegisteration(shamsiDate).First().Value);

其中getTodayNumberOfRegisteration是我添加到我的edmx模型的函数。

现在问题是:当我在SQL Server中执行存储过程而不是

 and csc.TFDateBackFromBankp= RTRIM( @TodayShamsiDate)

我设置了类似的东西:

 and csc.TFDateBackFromBankp= RTRIM( '1391/12/05')

此存储过程返回值6

但是当我从C#codebehind传递参数时,我得到返回值'0'

任何帮助,将不胜感激。

我通常这样做:在Add Function Import对话框中,选择你的存储过程并定义它返回一个Scalars集合:Int32

在此输入图像描述

然后在你的代码中,像这样调用它:

int value = db.getTodayNumberOfRegisteration(shamsiDate).First().Value;

这通常对我来说很好。

如果你没有将它定义为返回一个集合:Int32 ,那么你得到的值似乎是存储过程调用的返回值 ,例如受存储过程执行影响的行数(对于SELECT ,0或-1,因为您实际上没有插入,更新或删除任何行):

我发现了这个问题:我以这种方式设置了参数:

@TodayShamsiDate nvarchar

我应该指定nvarchar的长度

@TodayShamsiDate nvarchar(10)

我做到了,问题解决了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM