开发者

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

开发者 https://www.devze.com 2023-02-20 10:33 出处:网络
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 li开发者_StackOverflow中文版ttle bit 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 li开发者_StackOverflow中文版ttle bit confused. Do I have to use byte as type while setting this or not?


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.


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#.

0

精彩评论

暂无评论...
验证码 换一张
取 消