Solved

Convert NULL to EMPTY string

Posted on 2007-11-19
5
10,643 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 500 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

Independent Software Vendors: 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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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