8

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?

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132
Aditi
  • 1,188
  • 2
  • 16
  • 44

4 Answers4

10

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

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
9

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.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • Would something like this work then - `cmd.Parameters.Add("@isActive", SqlDbType.Bit).Value = False` – MaylorTaylor Dec 17 '14 at 17:05
  • 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`. – dakab Nov 30 '15 at 17:30
  • @dakab - 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`. – Damien_The_Unbeliever Nov 30 '15 at 17:35
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.

Alex
  • 8,827
  • 3
  • 42
  • 58
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.

jordanhill123
  • 4,142
  • 2
  • 31
  • 40