If the type of delete_existing
is a sqlserver 'bit' type, you can do :
var i = reader.GetOrdinal("delete_existing"); // Get the field position
deleteExisting = reader.GetBoolean(i);
or (but it will crash if delete_existing
can be DBNull
)
deleteExisting = (bool)reader["delete_existing"];
or better, this onebelow is DBNull
proof and returns false if the column is DBNull
deleteExisting = reader["delete_existing"] as bool? ?? false;
Otherwise if the database type is int
:
deleteExisting = (reader["delete_existing"] as int? == 1) ? true : false;
or if it is a varchar
deleteExisting = (reader["delete_existing"] as string == "1") ? true : false;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…