Are you sure "b" has a value that can be converted to double?
Update: There are tow problems in your code. This is how it should be IMHO:
object b = cmd.ExecuteScalar();
double result;
if((b != null) && double.TryParse(b.ToString(), out result){
}
else{
}