Answered by:
Null Value

Question
-
User-1499457942 posted
Hi
I have below code and value in m_location is Null but it is still going in the below condition
if (!string.IsNullOrEmpty(m_Location))
{
strQuery = strQuery + " " + m_Location;
}In Database when i run below command it shows no record but in field it shows Null
select * FROM [test].[dbo].[Data] where Location is null
Thanks
Thursday, September 20, 2018 4:16 PM
Answers
-
User753101303 posted
And your db is ? Once again the behavior you describe is exactly what you have if storing a 4 characters 'NULL' string rather than really a NULL value.
Try SELECT LEN(field) FROM YourTable WHERE Field='NULL' -- Or maybe LENGTH depending on your db
If it shows 4 rather than NULL you definitively stored a 'NULL' string in your db.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 20, 2018 5:33 PM
All replies
-
User753101303 posted
Hi,
This is what happens if m_Location or your db column is not null. Are you 100% sure you don't have a 4 character "null" string or may be whitespaces rather than really a string which is null ???
Try to show m_Location.Length. If it shows a value rather than throwing a NullReferenceException you do have a non null string.
Thursday, September 20, 2018 5:17 PM -
User-1499457942 posted
Hi
It shows NULL in field . When i run select statement for is null records it shows nothing. When i write select statement as field= 'NULL' then it shows records
Thanks
Thursday, September 20, 2018 5:25 PM -
User753101303 posted
And your db is ? Once again the behavior you describe is exactly what you have if storing a 4 characters 'NULL' string rather than really a NULL value.
Try SELECT LEN(field) FROM YourTable WHERE Field='NULL' -- Or maybe LENGTH depending on your db
If it shows 4 rather than NULL you definitively stored a 'NULL' string in your db.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 20, 2018 5:33 PM