Convert NULL to EMPTY string

I am using an SQL database in my ASP.NET application. I want to edit/insert new entries to the database using detailsview control. I might not enter information into all the fields, for example I might have a record only with FirtsName, but no LastName and no Phone. For the purpose of searching the database later I do not allow NULL as a field entry. Obviously, when I am trying to insert/edit a record with some empty fields I have an error. How can I convert NULL type data fields from detailsview into EMPTY strings before writing data to the SQL database? Thank you.

lmgreggAsked:
Who is Participating?
 
nisarkhanConnect With a Mentor Commented:
isnull(column_name, empty_string)

note: empty_string means: ''    <<<<(single quote  single quote)

isnull(column_name, '')
0
 
ptakjaCommented:
Or, you can replace empty_string with String.Empty which resolves to ""

You could also modify the table so an empty string ('') is the default for the field. Having a NULL constraint would prevent a user from overriding the default and inserting a null.
0
 
lmgreggAuthor Commented:
Where should I insert this code? I guess into DataBinding SUB? Thank you.
0
 
nisarkhanCommented:
in stored procedure or in your sql statement
0
 
nisarkhanCommented:
ptakja:

>>>Or, you can replace empty_string with String.Empty which resolves to ""

sql server will not understand the language of .net and its totally incorrect what you have said above.
0
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.

All Courses

From novice to tech pro — start learning today.