4
I need to return a field that is of the type bool
:
public List<TB_USUARIO> ListarTodos()
{
var strQuery = "select * from tb_usuario";
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader);
}
}
private List<TB_USUARIO> TransformaReaderEmListaObjetos(SqlDataReader reader)
{
var retornando = new List<TB_USUARIO>();
while (reader.Read())
{
TB_USUARIO tabela = new TB_USUARIO()
{
IDUSUARIO = reader["IDUSUARIO"] == DBNull.Value ? 0 : Convert.ToInt32(reader["IDUSUARIO"]),
NOME = reader["NOME"] == DBNull.Value ? string.Empty : reader["NOME"].ToString(),
LOGIN = reader["LOGIN"] == DBNull.Value ? string.Empty : reader["LOGIN"].ToString(),
SENHA = reader["SENHA"] == DBNull.Value ? string.Empty : reader["SENHA"].ToString(),
ADMINISTRADOR = (bool)reader["ADMINISTRADOR"] //este campo
};
retornando.Add(tabela);
}
reader.Close();
return retornando;
}
What is the value within
reader["ADMINISTRADOR"]
? Is there a problem? This column may benull
? What kind of it?– Maniero
is always coming as false
– Harry
What is the type of column in the database?
– Jéf Bueno
sql server database char(1) column, but I already have the answer: ADMINISTRATOR = (Reader["ADMINISTRATOR"] as string == "S") ? true : false
– Harry
You don’t need the
? true : false
. The sentence(reader["ADMINISTRADOR"] as string == "S")
already returns a boolean.– Jéf Bueno
@jbueno , thank you for all your help! immensely grateful
– Harry