Solved

Convert NULL to EMPTY string

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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