user2740190
user2740190

Reputation:

Convert SQL bit datatype to 1 or 0 in C# code

With Entity Framework from SQL I am accessing a field that its schema says "bit" Now I want to put it in C# code in an int I wrote something like this: Is this correct? or there are other ways?

int myResult = Convert.ToInt32(ef.thatField);

Upvotes: 0

Views: 3998

Answers (1)

Ramy M. Mousa
Ramy M. Mousa

Reputation: 5933

maybe you can try this :

    int myResult = ef.thatField ? 1 : 0;

Upvotes: 5

Related Questions