not getting stored procedure output variable through ExecuteReader
here my code-
using (SqlDat开发者_运维知识库aReader sqlDataReader = ExecuteReader(CommandType.StoredProcedure, StoredProcedures.AuthenticateUser, sqlParameter))
{
isAuthenticated = Convert.ToBoolean(sqlParameter[2].Value);
if (isAuthenticated)
{
if (sqlDataReader.Read())
{
User = new UserEntity();
DbHelper.GetEntity(sqlDataReader, User);
}
}
}
I always get isAuthenticated
as false because sqlParameter[2].Value
is null all the time but when I execute my query with ExecuteNonQuery
it gives me the value but in that case I can not fill the entity.suggest please.
I believe that output parameters are not available until you have read all the results from the DataReader. Try this instead:
using (SqlDataReader sqlDataReader = ExecuteReader(CommandType.StoredProcedure,
StoredProcedures.AuthenticateUser, sqlParameter))
{
var newUser = new UserEntity();
if (sqlDataReader.Read())
{
DbHelper.GetEntity(sqlDataReader, User);
}
isAuthenticated = Convert.ToBoolean(sqlParameter[2].Value);
if (isAuthenticated)
{
User = newUser;
}
}
精彩评论