0
即时尝试为我的.Net应用程序实现自定义角色提供程序。我试着去检查是否由用户添加的角色在数据库中已存在或者无法使用像捕获存储过程的返回值
SqlConnection sqlConnection = new SqlConnection(conn);
SqlCommand sqlCommand = new SqlCommand("aspnet_Roles_RoleExists", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@RoleName", SqlDbType.VarChar, 256).Value = "/";
sqlCommand.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 256).Value = roleName;
sqlCommand.Parameters.Add("@ReturnValue", SqlDbType.Int,4).Direction = ParameterDirection.ReturnValue;
try
{
sqlConnection.Open();
sqlCommand.ExecuteNonQuery();
int x = (int)sqlCommand.Parameters["@ReturnValue"].Value;
if ((int)sqlCommand.Parameters["@ReturnValue"].Value == 0)
...
的问题Asp.NET的角色提供的存储过程是,当我添加的角色如admin
并运行SP从数据库中手工像
DECLARE @return_value int
EXEC @return_value = [dbo].[aspnet_Roles_RoleExists]
@ApplicationName = N'/',
@RoleName = N'admin'
SELECT 'Return Value' = @return_value
它给了我正确的结果,但在应用程序,如果我尝试再次添加的角色admin
声明
(int)sqlCommand.Parameters["@ReturnValue"].Value
总是给我0
。任何人都可以引导我到是什么原因造成这种现象
重复的http://stackoverflow.com/questions/5412256/return-value-using-sqlcommand –
@SebastianMeine但即时不使用任何类的排序为'SafeDataReader' –
你有一个点那里... –