Why doesn't this simple code work?

Here is a snippet of code. I didn't post the rest of it because it all works. The only part that doesn't is my when I check to see if there is a value in a datetime field called "Problem" of the returned records and if there is, set it's background color to red. There are CSS classes called "red" and "blue" in my stylesheet. My if statement test just isn't doing what it should for some reason. One of returned records has a datetime value in it's Problem field, and the second doesn't. But they both come out either red or blue, when the first should be blue and the second red.
SqlConnection myConnection = new SqlConnection("server=localhost;" +
                                           "Trusted_Connection=yes;" +
                                           "database=mydb; " +
                                           "connection timeout=30");
        try
        {
            myConnection.Open();
            
                SqlDataReader myReader = null;
                SqlCommand myCommand = new SqlCommand("Select ID, PhoneNumber, Address, DollarAmt, Problem FROM Orders", myConnection);
                myReader = myCommand.ExecuteReader();
 myReader = myCommand.ExecuteReader();
                while (myReader.Read())
                {
                    String problem = myReader["Problem"].ToString();
                    String ID = myReader["ID"].ToString();
                    String bg = "";
                    if(problem != null || problem != ""){
                        bg = "red";    
                    }
                    else { bg = "blue"; }
                    Response.Write("<div id='section" + ID + "'>");
                    Response.Write("<ul id='item" + ID + "' class='" + bg + "' onclick='showOptions(\"buttons" + ID + "\");'>");

Open in new window

LVL 9
BobHavertyComhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
What is the database definition of the Problem column?
0
Lokesh B RDeveloperCommented:
Hi,

If Problem is not NULL then RED, ELSE BLUE.

You should add AND condition while checking for NULL.

           
        if(problem != null  &&  problem != "")
                    {
                          bg = "red";    
                    }
                    else 
                    {   
                          bg = "blue"; 
                    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BobHavertyComhAuthor Commented:
I knew it was something stupid where I just needed a second pair of eyes. I was working for too long yesterday and my brain apparently fought back. Thanks a bunch.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.