Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a property whose type in database is bit?

Tags:

c#

I have a column named source of type bit in my database. but I want to get set its value in my program. how can I do that? I know it was a simple doubt but I was little bit confused. Do I have to use byte as type while setting this or not?

like image 614
Febin J S Avatar asked Mar 28 '11 10:03

Febin J S


2 Answers

Use bool for representation bit from database:

public bool MyBitDbProperty {get;set;}

If you use SqlDataReader than use reader.GetBoolean(position) for bit type.

If you use any rdbms(like linq to sql), bit will mapped to bool by default.

like image 76
Andrew Orsich Avatar answered Oct 20 '22 00:10

Andrew Orsich


The bit database type will contain the values 0 and 1, and normally (you've not stated RDMS) corresponds nicely with the bool or Boolean types in c#.

like image 28
Jon Egerton Avatar answered Oct 19 '22 22:10

Jon Egerton