Read boolean values from DB?

后端 未结 5 848
时光说笑
时光说笑 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:23

    How about this?

    deleteExisting = (reader["delete_existing"] as int?) == 1;
    

    Boolean is probably the easist type to convert something to. Here's the 'Y', 'N' version:

    deleteExisting = string.Equals(reader["delete_existing"] as string, "Y", StringComparision.OrdinalIgnoreCase);
    

提交回复
热议问题