SqlString.ToString returns literal "Null" value

  • Thread starter Thread starter Anastasios Papadopoulos
  • Start date Start date
A

Anastasios Papadopoulos

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 said:
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
///
 
Herfried said:
I believe it is.



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top