Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I have this code that runs inside of a loop:

 

While nDataReader.Read()

strNewSnow = nDataReader!New_snow_24

strBaseDepth = nDataReader!Base_depth

strTopDepth = nDataReader!top_depth

strConditions = nDataReader!Conditions

End While

 

This works great, but if the value in the database is NULL, it craps out because it tries to set my string variable to null. If I use the debugger I can step through it and its all fine, but soon as i hit the null value it errors.

 

What is the best most efficient way to deal with this? I don't have to go through and put in a bunch of if statements do I?

 

thanks.

 

-JBD

Posted

So, the only way I can do this is like this?

 

nDataReader = comSQL.ExecuteReader(CommandBehavior.CloseConnection)

While nDataReader.Read()

If IsDBNull(nDataReader!New_snow_24) Then

strNewSnow = ""

Else

strNewSnow = nDataReader!New_snow_24

End If

If IsDBNull(nDataReader!Base_depth) Then

strBaseDepth = ""

Else

strBaseDepth = nDataReader!Base_depth

End If

If IsDBNull(nDataReader!top_depth) Then

strTopDepth = ""

Else

strTopDepth = nDataReader!top_depth

End If

If IsDBNull(nDataReader!Conditions) Then

strConditions = ""

Else

strConditions = nDataReader!Conditions

End If

End While

 

Yuck :) there is A LOT of these, kinda a pain :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...