By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

assigning db nulls to strings

P: n/a
Any reason to take this precaution ... ?

Dim s As String

s = IIf(.Item("MyField") Is DBNull.Value, "", .Item("MyField"))
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Using the named columns instead of indexes or .GetOrdinal is yucky. Also,
instead of "" , I'd recommend string.empty so you don't declare unnecessary
strings.

Otherwise, the main reason to do it is to ensure you don't throw a Null
reference exception.

HTH,

Bill
"John A Grandy" <johnagrandy-at-yahoo.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Any reason to take this precaution ... ?

Dim s As String

s = IIf(.Item("MyField") Is DBNull.Value, "", .Item("MyField"))

Nov 20 '05 #2

P: n/a
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
Any reason to take this precaution ... ?

Dim s As String

s = IIf(.Item("MyField") Is DBNull.Value, "", .Item("MyField"))

How do you distinguish between DBNull.Value and zero-length strings? If
there's no difference why do you allow Null values in the database?

Apart from that, I'd do it the way you did. Perhaps in a function:

function DBNull2String(byval o as object) as string
if o is dbnull.value then return ""
return o.tostring
end function
--
Armin

Nov 20 '05 #3

P: n/a
I have no control over the design & static pre-populating of the database.
I also have only very limited control over the dynamic populating of the
database.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
Any reason to take this precaution ... ?

Dim s As String

s = IIf(.Item("MyField") Is DBNull.Value, "", .Item("MyField"))

How do you distinguish between DBNull.Value and zero-length strings? If
there's no difference why do you allow Null values in the database?

Apart from that, I'd do it the way you did. Perhaps in a function:

function DBNull2String(byval o as object) as string
if o is dbnull.value then return ""
return o.tostring
end function
--
Armin

Nov 20 '05 #4

P: n/a
"John A Grandy" <johnagrandy-at-yahoo.com> schrieb
I have no control over the design & static pre-populating of the
database. I also have only very limited control over the dynamic
populating of the database.


Ah, I see.

(as your problem seems to be solved, there's nothing else I can say ;-) )
--
Armin

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.