Read boolean values from DB?

后端 未结 5 893
时光说笑
时光说笑 2020-12-16 15:07

In C#, using SqlDataReader, is there a way to read a boolean value from the DB?

while (reader.Read())
{
    destPath = reader[\"destination_path\"].ToString(         


        
5条回答
  •  忘掉有多难
    2020-12-16 15:34

    If you are using CASE in SELECT and want to use GetBoolean then use CAST to change the column to bit before reading.

    For eg:

    SELECT CAST((CASE WHEN [Condition] THEN 1 ELSE 0 END) as bit) FROM Table_Name
    

    then you can use

    reader.GetBoolean(0)
    

提交回复
热议问题