473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SqlString.ToString returns literal "Null" value

Hello all,

I have statements like the following in my Property Get:

Public Property AccountNumber() As String
Get
Return MyClass.AccountNumber.ToString
End Get
blah blah
End Property

where MyClass.AccountNumber is SqlString

The issue is that if MyClass.AccountNumber is null (in the database) my
property shown above returns a literal "Null" string when called.

Is this by design? How can I avoid it? I think returning an empty string
would be more appropriate than a value of "Null"...

Thanks in advance...

--
Anastasios Papadopoulos a.k.a. Cascader, Athens - Greece
Nov 21 '05 #1
2 2867
"Anastasios Papadopoulos" <tp****@salesmanager.gr> schrieb:
Public Property AccountNumber() As String
Get
Return MyClass.AccountNumber.ToString
End Get
blah blah
End Property

where MyClass.AccountNumber is SqlString

The issue is that if MyClass.AccountNumber is null (in the database) my
property shown above returns a literal "Null" string when called.

Is this by design?
I believe it is.
How can I avoid it? I think returning an empty string
would be more appropriate than a value of "Null"...


Null values have different semantics than zero-length strings.

Workaround:

\\\
If AccountNumber.IsNull Then
Return ""
Else
Return AccountNumber.Value
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2
Herfried K. Wagner [MVP] wrote:
"Anastasios Papadopoulos" <tp****@salesmanager.gr> schrieb:
Public Property AccountNumber() As String
Get
Return MyClass.AccountNumber.ToString
End Get
blah blah
End Property

where MyClass.AccountNumber is SqlString

The issue is that if MyClass.AccountNumber is null (in the database)
my property shown above returns a literal "Null" string when called.

Is this by design?

I believe it is.
How can I avoid it? I think returning an empty string would be more
appropriate than a value of "Null"...

Null values have different semantics than zero-length strings.

Workaround:

\\\
If AccountNumber.IsNull Then
Return ""
Else
Return AccountNumber.Value
End If
///

Thank you very much for your reply.
I was afraid I might have to use something so ugly as all those Ifs in
my code... To many places to add checks and so many CPU cycles to
execute it... There should be something else, but thank's anyway.

--
Anastasios Papadopoulos a.k.a. Cascader, Athens - Greece
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Denzil | last post by:
Hi, I am retrieving my DB values and setting them in the MyRS::DoFieldExchange(CFieldExchange* pFX) function. One of these records is a Long datatype and could be "Null" in the DB table. The...
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
3
by: Robb Gilmore | last post by:
Hello, We have a C#.NET app which is calling a Java webservice. We use the wsdl file exportted from the java webservice to create our web-reference in Visual Studio. We are able to create the...
8
by: Brian | last post by:
This is causing me to not be able to create a relation in my dataset. Here's my code: dc1 = ds.Tables .Columns ; dc2 = ds.Tables .Columns ; dr1 = new System.Data.DataRelation...
11
by: MLH | last post by:
I have 2 lines in a procedure that assign MyVariant a value - line #238 and line #491. When line #238 runs, the value is 152. When line #491 runs, the DLookup function returns Null. I would expect...
1
by: H | last post by:
Just trying to create a basic xmlhttpobject. However, the following always returns null xmlhttpobj = New ActiveXObject("Microsoft.XMLHTTP") (it is Microsoft. and not Msxml2. I've already...
2
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
7
by: monika varshney | last post by:
I have to read a database using dataset. My database has some null values. My code is working fine when there is a value in the database. But when there is a null value in the database, dataset...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.