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

  • Thread starter Thread starter cj2
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
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
 
Back
Top