Null checking for get methods of a datareader?

Hello
   Is there a way to error check the null value of fields returned in the results of an SQL query in ASp.NET. Reason this is important is that the Get methods of the data reader expect the fields to have non-null values.

For instance I need to add the null error checking for the following line of code:
gotName= sreader.GetString(sreader.GetOrdinal("Name")).ToString() <----------wont work if this field was null
 txtCustomer.text=gotName

Also, can someone suggest me a good book on ASP.NET programming that deals with issues like Datareader methods etc ,sorta like a bit more than a beginner but not quite an advanced reference I guess.

thanx
LuckyLucksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mikal613Commented:
gotName= sreader.GetString(sreader.GetOrdinal("Name") & "").ToString()
0
Mikal613Commented:
& "" 

Takes away the null

oe inyour query you can also add the condition where Blah is not null
0
willcode4coffeeCommented:
I wrote a simple overloaded method called NullSafe():

Public Shared Function NullSafe(ByVal Value)
        Return NullSafe(Value, TypeCode.String)

    End Function

    Public Shared Function NullSafe(ByVal Value As String) As String

        If Value Is System.DBNull.Value Then
            Return New String("")
        Else
            Return Value

        End If
    End Function

This will return a empty string or zero if a value is null.

M@
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

willcode4coffeeCommented:
To use NullSafe():

Value = NullSafe(Value)

or sMyVal = NullSafe(Value)

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Arthur_WoodCommented:
Rocky Lhotka, in his EXCELLENT book "Visual Basic.NET Business Object" builds what he calls a 'SafeDatraReader' class, that extends the standard DataReader, to not only handle null values, but also to handle date intelligently, and several other 'gotchas'

Rockford Lhotka
Expert One-on-One Visual Basic.NET Business Objects
ISBN: 1590591453
Pub. Date: June 2003
Publisher: APress

don't be put off by the Expert reference in the title.  A very good book to have in your library.

AW
0
fahimnxbCommented:
Dear LuckyLucks,

here is what u need...

If Not isDBNULL(sreader.GetString(sreader.GetOrdinal("Name"))) Then
           txtCustomer.text=gotName
EndIf

Regards,
Me
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.