开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜