C# convert bit to boolean
DataReader.GetBoolean(x)
or
Convert.ToBoolean(DataRow[x])
Depending on how are you performing the SQL queries it may depend. For example if you have a data reader you could directly read a boolean value:
using (var conn = new SqlConnection(ConnectionString))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT isset_field FROM sometable";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
bool isSet = reader.GetBoolean(0);
}
}
}
How are you extracting the fields from the database?
The SqlDataReader
class has a GetBoolean
method which does the translation for you:
bool yourBoolean = reader.GetBoolean(reader.GetOrdinal("Your_Bit_Column"));