Skip to content

How do i cast object from data reader to boolean value ?

Nepethya Rana

Asked Sep 15, 2017, 9:38 AM EDT1 answer
Share
LinkedInX
how do i cast object from data reader to boolean value ?
Employee has IsActive property which is Bool data type. 
 
I tried followings but got exception .
 
Code
emp.IsActive = (bool)rdr["Is_Active"];
emp.IsActive = Convert.ToBoolean(rdr["Is_Active"]);

 var i = rdr.GetOrdinal("Is_Active");
emp.IsActive = rdr.GetBoolean(i);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    My bad. Code works fine. Error was due to other things
    0