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?

4
  • 2
    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 ?" Commented Mar 6, 2013 at 9:22
  • I agree, Boolean, as it's stored as either 0 or 1. Commented Mar 6, 2013 at 9:25
  • 1
    @Freeman wouldn't a boolean take true or false? and bit takes 1, 0.. Commented Mar 6, 2013 at 9:26
  • 1
    Exactly, so your question is? Commented Mar 6, 2013 at 9:26

4 Answers 4

13

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

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

Would something like this work then - cmd.Parameters.Add("@isActive", SqlDbType.Bit).Value = False
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 - 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.
4

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.

Comments

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.

1 Comment

This doesn't take into account that the OP was asking for SQLDbType which does not include a Boolean type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.