Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

How do i Handle a Case of DBNull so that I exit my application gracefully

I have the  c#  method stated below:

var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        if ((string)reader?["formexecutex"] != null)
                        {
                            LoginDetails.staticformexecute = (string)reader["formexecutex"];
                            LoginDetails.staticaddbutton = (string)reader["addbuttonx"];
                            LoginDetails.staticupdatebutton = (string)reader["updatebuttonx"];
                            LoginDetails.staticdeletebutton = (string)reader["deletebuttonx"];

                            results.Add(model);
                        }
                        else
                        {
                            StandardMessages.FormPermission();
                        }
                    }

Open in new window


During Execution  variable formexecutex can be   "Y" ,  "N"  OR may not even exist  ie is DBNull

How do handle the  DBNull  case to use the else  clause of the If Statement

See  the error i got while trying

User generated image
Thanks

Olukay
ASKER CERTIFIED SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Olukayode Oluwole

ASKER

Thanks    Got it!!!!!
Happy to help.  Thanks for the points.