开发者

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;
     }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜