check if field is empty/nothing/null????

C

cj2

if myodbcreader.hasrows then
if myodbcreader("code").trim = "" or myodbcreader("reas").trim = "aVAL"
then
do something
endif
endif

Is this the appropriate way to test if the code field is something other
an a value? I find I can also say if myodbcreader("code").trim = nothing.

What about or vs orelse? I've heard I should use orelse yet I don't
know why.
 
Z

zacks

if myodbcreader.hasrows then
        if myodbcreader("code").trim = "" or myodbcreader("reas").trim = "aVAL"
then
                do something
        endif
endif

Is this the appropriate way to test if the code field is something other
an a value?  I find I can also say if myodbcreader("code").trim = nothing.

What about or vs orelse?  I've heard I should use orelse yet I don't
know why.

Orelse means that if the first condition is true, then don't bother to
check the next condition.

Best way to check to see if a column in an ODBCDataReader is null is
to use the IsDBNull method.
 
C

cj2

isdbnull reports false when the field is = "" or " ". What I was
trying to say when I said "when a field is something other than a value"
was I don't consider "" or " " a value.
 
S

Stephany Young

You've got a number of choices about how to deal with this issue.

The first thing to do is investigate the methods exposed by the
OdbcDataReader class.

The IsDBNull and GetString methods jump out immediately and used in
conjunction with the String.Trim and String.IsNullOrEmpty methods you should
be able to develop a very robust handler.
 
J

JimmyKoolPantz

isdbnull reports false when the field is = "" or "  ".  What I was
trying to say when I said "when a field is something other than a value"
was I don't consider "" or "  " a value.







- Show quoted text -

you could do something like this

'declaration
Dim s As String

'remove blank spaces
s = TextBox1.Text.Trim

'test for values
If (s = String.Empty) Then
MsgBox("JimmyKoolPantz is the man")
Else
MsgBox("Textbox1 has a value")
End If
 

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

Top