How can I make an if if DataBase data is True or False

-2

How can I do an if checking if the data in a column in the DataBase table is True or False?

For example:

using (SqlCommand cmd = new SqlCommand($"SELECT LoginID,Award FROM Sys_Usuarios_Award WHERE LoginID={login.LoginId} and Award='true ou false'", connection))

What I have in mind:

if (Award == True){
Console.WriteLine("True");
}else{
Console.WriteLine("False");
}

Award is the column I got in the SQLCommand. In short I wanted to do an if with the bit data of a column but I do not know how to do it.

    
asked by anonymous 12.03.2018 / 14:45

1 answer

1

A simple way is to use the SqlDataReader example below:

using (var comando = connection.CreateCommand())
{
    comando.CommandText = $"SELECT LoginID,Award FROM Sys_Usuarios_Award WHERE LoginID={login.LoginId}";
    var reader = comando.ExecuteReader();

    if (reader.Read())
    {
        if ((bool)reader["Award"])
        {
            Console.WriteLine("True");
        }
        else
        {
            Console.WriteLine("False");
        }
    }
}
    
12.03.2018 / 15:26