SQL Helper类为SQL输出参数提供每次空值 [英] SQL Helper class giving each time null value for SQL output paramter

查看:57
本文介绍了SQL Helper类为SQL输出参数提供每次空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Microsft SQL Helper Utlity类从代码调用存储过程,并且当从SQL服务器执行时,存储过程正在给出适当的值,每次获取null值。
下面的
是我的代码。 />

I am calling store procedure from code using Microsft SQL Helper Utlity class and getting each time null value while store procedure is giving proper value when executing from SQL server.
below is my code.

Create Proc [dbo].[SP_GetUserNumber]
(
 @UserID AS VARCHAR(10)= '',
 @RetValue As VARCHAR(50) OUTPUT
)
As
BEGIN
    select @RetValue=MobNumber from tbl_User where userid=@UserID
END





C#代码



C# code

SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["SQLConn"]);
			
			SqlParameter[] SqlParam = new SqlParameter[2];
            SqlParam[0] = new System.Data.SqlClient.SqlParameter("@UserID", SqlDbType.VarChar);
            SqlParam[0].Value = strUserID;

            SqlParam[1] = new System.Data.SqlClient.SqlParameter("@RetValue", SqlDbType.VarChar);
            SqlParam[1].Direction = ParameterDirection.Output;

            

            int i = SqlHelper.ExecuteNonQuery(sqlcon, "SP_GetUserNumber", SqlParam);

            string[] arReturnParms = new string[1];
            arReturnParms[0] = SqlParam[1].Value.ToString();

推荐答案

看看这个< br $> b $ b

ADO.NET - 如何使用输出参数调用存储过程? [ ^ ]


SQL Helper Class Microsoft .NET Utility [ ^ ]


检查是否有表中重复的userID值。如果它返回多于一个记录,那么它将抛出一个异常,结果为null。



您也可以尝试使用ExecuteScaler而不是ExecuteNonQuery。
Check if there is duplicate userID value in the table. If it is returning more then one record then it will throw an exception resulting null.

You can also try with ExecuteScaler instead of ExecuteNonQuery.


这篇关于SQL Helper类为SQL输出参数提供每次空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆