Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Detecting SQL Null values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fred Herring - 16 Dec 2004 18:27 GMT
When a sql column is read that contains a null, how is that detected.  A sql
null value does not appear to be a system.dbnull.value.  What data type is
used to detect the presence of a sql null.

Thanks,
Fred Herring
Herfried K. Wagner [MVP] - 16 Dec 2004 18:49 GMT
"Fred Herring" <FredHerring@discussions.microsoft.com> schrieb:
> When a sql column is read that contains a null, how is that detected.  A
> sql
> null value does not appear to be a system.dbnull.value.  What data type is
> used to detect the presence of a sql null.

Depending on the datatype, you can compare with 'Sql<datatype>.Null'.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

Jinmin Yang - 16 Dec 2004 23:05 GMT
Or get another solution from SQL query:
 SELECT
     CASE WHEN (Field1 IS NULL) THEN '' ELSE Field1 END AS Field1,
     CASE WHEN (Field2 IS NULL) THEN 0 ELSE Field2 END AS Field2   
 FROM myTable   
 --Field1 data type is nvarchar   
 --Field2 data type is numeric
So "null value does not appear in your codes.

> "Fred Herring" <FredHerring@discussions.microsoft.com> schrieb:
> > When a sql column is read that contains a null, how is that detected.  A
[quoted text clipped - 3 lines]
>
> Depending on the datatype, you can compare with 'Sql<datatype>.Null'.
Jim Hughes - 16 Dec 2004 23:51 GMT
Or use COALESCE

Select  COALESCE(Field1,'') as Field1, COALESCE(Field2,0) as Field2 FROM
myTable

From the BOL:

COALESCE
Returns the first nonnull expression among its arguments

COALESCE(expression1,...n) is equivalent to this CASE function:
CASE
  WHEN (expression1 IS NOT NULL) THEN expression1
  ...
  WHEN (expressionN IS NOT NULL) THEN expressionN
  ELSE NULL

> Or get another solution from SQL query:
>  SELECT
[quoted text clipped - 14 lines]
>>
>> Depending on the datatype, you can compare with 'Sql<datatype>.Null'.
Matthew H. Toney - 17 Dec 2004 17:46 GMT
Is you use IsDBNull(field) it should return the results correctly for you...

> When a sql column is read that contains a null, how is that detected.  A
> sql
[quoted text clipped - 3 lines]
> Thanks,
> Fred Herring

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.