"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
Go Back  Xtreme Visual Basic Talk > > > "" Is Really Stupid and Should Feel Bad About Itself


Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2010, 07:35 PM
evilfindish evilfindish is offline
Newcomer
 
Join Date: Oct 2009
Posts: 3
Angry "" Is Really Stupid and Should Feel Bad About Itself


Actually, my title is slightly deceiving in that it's just a problem on my side. When programming I didn't realize that "" was different from System.DBNull. This clearly led to some problems. Is there a way to either convert a cell to DBNull, tell if a cell is either "" or DBNull, or even just use an OR operator successfully as I have had trouble with this.

Thank you for your gracious help,

evilfindish
Reply With Quote
  #2  
Old 01-26-2010, 12:27 PM
HardCode's Avatar
HardCode"" Is Really Stupid and Should Feel Bad About Itself HardCode is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2004
Location: New Jersey
Posts: 3,339
Default

Code:
If String.IsNullOrEmpty(myStringVariable) Then ' Do something End If
__________________
DON'T CLICK HERE

Useful forum tags: [VB][/VB], [CODE][/CODE], [HTML][/HTML]
Reply With Quote
  #3  
Old 02-01-2010, 01:46 PM
shaul_ahuva"" Is Really Stupid and Should Feel Bad About Itself shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

In addition to what HardCode said, you'll sometimes have to worry about what the data will be like coming from a database. Nothing/null is not the same as DBNull (don't even get me started on why there are two ways of indicating "null" in .NET), and therefore a test for "null" doesn't always work. You could use nullable types, but Nullable(Of T) is just plain icky in VB when compared to the C# shortand.

My solution? A simple function that does the test for you:

Code:
Public Shared Function IsNull(o As Object) As Boolean
    Return o Is Nothing OrElse o.Equals(DBNull.Value)
End Function
You could obviously expand the function to account for other values (empty string, 0, MinValue, etc.) being treated as null.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself "" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
 
"" Is Really Stupid and Should Feel Bad About Itself
"" Is Really Stupid and Should Feel Bad About Itself
 
-->