DbType equivalent to SqlDbType.Bit
Asked Answered
P

4

9

Does anyone know what is the DbType equivalent to SqlDbType.Bit?

I am trying to convert

param[0] = new SqlParameter("@Status", SqlDbType.Bit);
param[0].Value = Status;

to

db.AddInParameter(dbCommand, "@Status", <DbType dbType>, Status);

but I don't know which DbType to use to represent a single Bit. Any ideas?

Poppas answered 6/3, 2013 at 9:22 Comment(4)
a boolean perhaps? Altough the DbType is Bit and the .NET type is bool, so what do you mean by "DbType equivalent to SqlDbType.Bit ?"Stealer
I agree, Boolean, as it's stored as either 0 or 1.Crimpy
@Stealer wouldn't a boolean take true or false? and bit takes 1, 0..Poppas
Exactly, so your question is?Stealer
R
12

The database type bit is represented as a boolean on the server side, so the corresponding DbType value is DbType.Boolean.

Reposition answered 6/3, 2013 at 9:27 Comment(0)
S
10

DbType.Boolean:

A simple type representing Boolean values of true or false.

SqlDbType.Bit:

Boolean. An unsigned numeric value that can be 0, 1, or null.

Their description's don't quite match up, but since Bit is described as being a Boolean, it's the most appropriate match.

Salk answered 6/3, 2013 at 9:26 Comment(3)
Would something like this work then - cmd.Parameters.Add("@isActive", SqlDbType.Bit).Value = FalsePrearrange
Is it most appropriate? C# does know null, as do nullable BIT fields in SQL. SQL Server, for instance, accepts 0/1/NULL only rather than true/false.Escalade
@Escalade - there are various issues here that I didn't include in my answer - such as the fact that SQL Server doesn't have an actual boolean data type (bit is described in documentation as a numeric type) and that, if SQL Server were to implement the proper (SQL Standard) boolean data type then, due to its use of three-valued logic, that type should support true, false and unknown, plus the (standard for every type) absence of a value via null.Salk
O
3

http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.aspx

enum SqlDbType - Bit: Boolean. An unsigned numeric value that can be 0, 1, or null.

Overreach answered 6/3, 2013 at 9:27 Comment(0)
I
2

From http://msdn.microsoft.com/en-us/library/fhkx04c4, I would say DbType.Boolean A simple type representing Boolean values of true or false.

Induplicate answered 6/3, 2013 at 9:28 Comment(1)
This doesn't take into account that the OP was asking for SQLDbType which does not include a Boolean typePrearrange

© 2022 - 2024 — McMap. All rights reserved.