存储过程:
------------------------------------
--用途:检查用户是否已经存在
------------------------------------
CREATE PROCEDURE UserInfo_Exists
@userName varchar(50)
AS
DECLARE @TempID int
SELECT @TempID = count(1) FROM [UserInfo] WHERE userName=userName
IF @TempID = 0
RETURN 0
ELSE
RETURN 1
GO
--如果用户存在,则返回1,反之返回0
--------------------------------------------------------------
asp.net调用代码:
SqlParameter[] parameters = {
new SqlParameter("@userName", SqlDbType.VarChar,50),
new SqlParameter("@ReturnValue", SqlDbType.Int,4) };
parameters[0].Value = '用户账号';
parameters[1].Direction = ParameterDirection.ReturnValue;
return DbHelperSQL.ExistsProcedure("UserInfo_Exists", parameters);
需要实现功能:如果用户存在,则返回1,反之返回0
出现的问题:
1:返回null, 我是新手,怎么都检查不出来问题,希望知道的能指点下,先谢了
DbHelperSQL代码:
public static bool ExistsProcedure(string procName, SqlParameter[] cmdParms)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
PrepareCommand(cmd, connection, null, procName, CommandType.StoredProcedure, cmdParms);
int result = Convert.ToInt16(cmd.ExecuteScalar());
cmd.Parameters.Clear();.
return result==0?false:true;
}
catch (SqlException ex)
{
throw ex;
}
}
}