You can ofcourse do a direct cast. Usually if you do a ExecuteScalar() you know what the query is and what datatype it should return.
The Convert class will try to make sense out of more values than a cast will do so it might be an option but it still can be an issue.
If you expect the result to not always return a bool you should place the cast (or use of Convert.ToBoolean) inside a try catch block and catch the InvalidCastException.
bool b; object o = sqlcommand.ExecuteScalar(); try { b = (bool)o; //b = Convert.ToBoolean(o); } catch (InvalidCastException ex) { // Handle incorrect data }
|