[dba-VB] Checking for NULL and empty strings

Charlotte Foust cfoust at infostatsystems.com
Fri May 25 09:52:27 CDT 2007


And once you have tested the IsNull, you can use the OrElse operator to
check for an empty string like this:

If Not addrRow.IsMAddress2Null OrElse addrRow.MAddress2.Trim.Length > 0
Then 

The AndAlso and OrElse operators are a treasure because they only
evaluate that part of the expression if the first part succeeds.

Charlote Foust

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte
Foust
Sent: Friday, May 25, 2007 7:32 AM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] Checking for NULL and empty strings

If you're using a typed dataset, string and some other data types have
an Is<FieldName>Null property that you can test.  Cast the record as a
row of the appropriate datatype to use it.  Then you should be able to
use something like addrRow.IsMAddress2Null to check it.

Charlotte Foust

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of David Emerson
Sent: Thursday, May 24, 2007 5:52 PM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] Checking for NULL and empty strings

Thanks David,

I originally had a similar syntax but was hoping that there was an
shorter method.

David

At 25/05/2007, you wrote:
>Here's a function I wrote (actually I wrote it for C#, but crossed it 
>over to vb.net)
>
>     Public Function IsNull(ByVal strInput As String, ByVal strReplace 
>As
>String) As String
>         'This works like SQL server's IsNull, not VB/VBA. In VB/VBA it

>is known as Nz()
>         If (strInput Is Nothing) Then
>             Return strReplace
>         Else
>             If strInput = "" Then
>                 Return strReplace
>             Else
>                 Return strInput
>             End If
>         End If
>     End Function
>
>
>On 5/24/07, David Emerson <newsgrps at dalyn.co.nz> wrote:
> >
> > Group,
> >
> > I am wanting to test the value of a field from a data source.  If it

> > is NULL or "" then do one thing, otherwise do another.  Here is
> my vb.netcode:
> >
> >          If IsDBNull(Fields("MAddress2").Value) Or 
> > (Fields("MAddress2").Value = "") Then
> >              Me.txtMailAddress.DataField = "=MAddress1"
> >          Else
> >              Me.txtMailAddress.DataField = "=MAddress1" + Chr(34) + 
> > ", " + Chr(34) + " + MAddress2"
> >          End If
> >
> > The error message is "
> >
> > Operator '=' is not defined for type 'DBNull' and string "".
> >
> > What is the correct syntax for this?
> >
> >
> > Regards
> >
> > David Emerson
> > Dalyn Software Ltd
> > Wellington, New Zealand
> > _______________________________________________
> > dba-VB mailing list
> > dba-VB at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/dba-vb
> > http://www.databaseadvisors.com
> >
> >
>_______________________________________________
>dba-VB mailing list
>dba-VB at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/dba-vb
>http://www.databaseadvisors.com

_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com





More information about the dba-VB mailing list