?
Solved

Convert NULL to EMPTY string

Posted on 2007-11-19
5
Medium Priority
?
10,654 Views
Last Modified: 2010-09-07
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.

0
Comment
Question by:lmgregg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Accepted Solution

by:
nisarkhan earned 2000 total points
ID: 20314154
isnull(column_name, empty_string)

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

isnull(column_name, '')
0
 
LVL 14

Expert Comment

by:ptakja
ID: 20314181
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
 

Author Comment

by:lmgregg
ID: 20314203
Where should I insert this code? I guess into DataBinding SUB? Thank you.
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20314230
in stored procedure or in your sql statement
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20314390
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question