Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace nulls with empty strings from DataReader

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
0
0
US
I am working on a program to manipulate data from a MS SQL 2000 database. However, I am having problems differentiating between nulls and empty strings, both of which I find in my database. I would like to covert all the nulls returned by my SQL query into blank strings to make data checking easier later on.

Here is the code that gathers the data:
Code:
Dim cmd As New SqlCommand("Select * From ClientTable", IntakeConnection)
Dim IntakeData As SqlDataReader = cmd.ExecuteReader()

I have a bunch of If-Then statements to act if the data is not null. For example:
Code:
If IntakeData.Item("SSN") <> "" Then XML.WriteElementString("soc_sec_no", IntakeData.Item("SSN"))

But if the SSN field is null instead of blank, I get errors. I would prefer not to check for nulls & blanks each time; but instead coverting them all to blanks.
 
OK. It was almost 2 am, and I replied without reading your post properly - that's my excuse [smile] - but well done all the same, and sorry if I caused you to doubt your solution.

Looking back over it, you typed in not and I even corrected it to Not - and I still got it wrong. That takes genius [ponder]
 
Comment censored.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Go get a module. Module-lover. ;-)

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Who's that? Zorro with his eyes closed?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
The greatest geniuses are unknown in their time. Therefore, I am a genius.
 
Now you are going to face the wrath of chrissie - you are a brave man, Bob.
 
Fear of the unknown is undifferentiated. As such, I fear chrissie as much as I fear death, knowing equally little about each. (Oh no.......)
 
Bob, I wouldn't want to be in your shoes tomorrow - in fact I don't think I'll even be brave enough to switch my computer on. [smile]
 
earthandfire, in case someone after the fact is trying to make sense out of this thread: after reading more carefully, you're not suggesting that AndAlso works just like And, as I had stated. So, I'm wrong about that. On the other hand, the statement
Code:
Not IsDBNull(IntakeData.Item("Middle_Name")) OrElse IntakeData.Item("Middle_Name")) <> ""
will allow all values to pass, since all values are either not null or not blank strings, whether or or orelse is used.

As for chrissie and the genius thing, perhaps he'll just put it down to the mindless blundering of the ignorant. :)

Bob

p. s. But I am still a genius.
 
[smile] ... and as I said it was 2 am (its 1 am now - so I'm signing off before I reply to any other threads and get it wrong again)

 
I didn't mean to flog a dead horse, but want to make sure that any errors in fact in the thread are corrected.

Bob
 
I fear chrissie as much as I fear death

Death is easy. It is the beginning of the end andalso the end of the beginning. Fear me and death shall be fun. Worship me and... I will love you forever.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top