Reputation: 83
I have a requirement to INSERT the actual word "NULL" as a text value in a SQL Server database. Is this possible? If so, how do I get that done using C#?
Upvotes: 0
Views: 331
Reputation: 374
Use the IsNull() SQL Server function to ensure a column always returns text. That way you don't even have to deal with NULL in C# if you don't want to.
For example:
select isNull(TextColumn, 'NULL') as NeverNull
In C# you can use the following pattern to handle nulls as you desire:
string NeverNull = NullableVariable is null ? "NULL" : NullableVariable;
Upvotes: 1