Skip to content
Advertisement

IsNullOrEmpty with an empty value still go into the loop

I’m currently trying to compare in C# a value I get from my database, and i use “IsNullOrEmpty” to check if the value is, well, null or empty.

When the value in the database is “null”, no problem.

However, when the value is “empty”, I still enter the loop;

I add an empty value:

  update Planning
  set Repas2 =''
  where jour = '01/11/19' and Matricule='601'

And now the debug :

enter image description here

as you can see, “Repas2” is empty but I still go in the loop.

Anyone know why I’m doing this?

Advertisement

Answer

Use string.IsNullOrWhiteSpace(...) instead

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement