LINQ Queries: handling nulls

Quite often when querying databases using data from text boxes, you can run into problems dealing with a blank string and fields containing a null.

A field in a table may contain a null which could also mean a blank field but you can run into problems when you are trying to query a condition on the field.

This example solved the problem;

All i’m doing in the LINQ query is checking if the textbox (a string) is blank, if it is then I pass a null to condition.

If you are planning to use a null when the field is blank, then also when you are saving data to the field you need to use the followin example;

This entry was posted in C# Development. Bookmark the permalink.