Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Testing textbox for null


Message #1 by "Hugh McLaughlin" <hugh@k...> on Fri, 21 Jun 2002 23:30:45
Hello Everyone and thanks for your help in advance.  I am working on an 
application that builds a SQL query based on whether data has been 
entered into a text field.  An example is located at:

http://www.famb.org/roster.aspx

Basically, the idea is to check and see if there is data entered into the 
first or last anme fields and build the query accordingly.  The code is:

Dim SQL As String = "Select * From tblMembers"

If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then 
    SQL=SQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

However, whether I enter data into the last name field or not, the WHERE 
clause that should be inserted only if data is present, continues to be 
inserted.  Obviously, my "If...Then" is not working properly, but I don't 
understand why.  Any help would be greatly appreciated.  Thanks.
Message #2 by "James Scot Johnston" <scotj@i...> on Fri, 21 Jun 2002 15:26:17 -0700
I believe from a quick look you want to use the [AND} operator not [OR]
because you want to fail if both condition of "" or null are met =3D)

J. Scot
IronSpire Inc.

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Friday, June 21, 2002 4:31 PM
To: ASP+
Subject: [aspx] Testing textbox for null


Hello Everyone and thanks for your help in advance.  I am working on an
application that builds a SQL query based on whether data has been
entered into a text field.  An example is located at:

http://www.famb.org/roster.aspx

Basically, the idea is to check and see if there is data entered into
the
first or last anme fields and build the query accordingly.  The code is:

Dim SQL As String =3D "Select * From tblMembers"

If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then
    SQL=3DSQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

However, whether I enter data into the last name field or not, the WHERE

clause that should be inserted only if data is present, continues to be
inserted.  Obviously, my "If...Then" is not working properly, but I
don't
understand why.  Any help would be greatly appreciated.  Thanks.
Message #3 by "Hugh McLaughlin" <hugh@k...> on Sat, 22 Jun 2002 00:07:42
Well actually I think OR is the right way, but I tried AND and received 
the same results.

> I believe from a quick look you want to use the [AND} operator not [OR]
because you want to fail if both condition of "" or null are met =3D)

J. Scot
IronSpire Inc.

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Friday, June 21, 2002 4:31 PM
To: ASP+
Subject: [aspx] Testing textbox for null


Hello Everyone and thanks for your help in advance.  I am working on an
application that builds a SQL query based on whether data has been
entered into a text field.  An example is located at:

http://www.famb.org/roster.aspx

Basically, the idea is to check and see if there is data entered into
the
first or last anme fields and build the query accordingly.  The code is:

Dim SQL As String =3D "Select * From tblMembers"

If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then
    SQL=3DSQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

However, whether I enter data into the last name field or not, the WHERE

clause that should be inserted only if data is present, continues to be
inserted.  Obviously, my "If...Then" is not working properly, but I
don't
understand why.  Any help would be greatly appreciated.  Thanks.
Message #4 by "Albert Davis" <albertdavis@h...> on Fri, 21 Jun 2002 23:59:04 -0400
Try both in a response.write as a boolean condition to get the results, this 
will tell you what is going on in the evaluation..

>From: "Hugh McLaughlin" <hugh@k...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] RE: Testing textbox for null
>Date: Sat, 22 Jun 2002 00:07:42
>
>Well actually I think OR is the right way, but I tried AND and received
>the same results.
>
> > I believe from a quick look you want to use the [AND} operator not [OR]
>because you want to fail if both condition of "" or null are met =3D)
>
>J. Scot
>IronSpire Inc.
>
>-----Original Message-----
>From: Hugh McLaughlin [mailto:hugh@k...]
>Sent: Friday, June 21, 2002 4:31 PM
>To: ASP+
>Subject: [aspx] Testing textbox for null
>
>
>Hello Everyone and thanks for your help in advance.  I am working on an
>application that builds a SQL query based on whether data has been
>entered into a text field.  An example is located at:
>
>http://www.famb.org/roster.aspx
>
>Basically, the idea is to check and see if there is data entered into
>the
>first or last anme fields and build the query accordingly.  The code is:
>
>Dim SQL As String =3D "Select * From tblMembers"
>
>If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then
>     SQL=3DSQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
>End If
>
>However, whether I enter data into the last name field or not, the WHERE
>
>clause that should be inserted only if data is present, continues to be
>inserted.  Obviously, my "If...Then" is not working properly, but I
>don't
>understand why.  Any help would be greatly appreciated.  Thanks.

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Message #5 by nzulfiqar <nzulfiqar@g...> on Sat, 22 Jun 2002 09:13:46 +0400
Hi, check the name of last name field. I think may be u r entering value in
last name filed and checking it but control name is FirstName where u r
entering value. 

-----Original Message-----
From: Albert Davis [mailto:albertdavis@h...] 
Sent: Saturday, June 22, 2002 7:59 AM
To: ASP+
Subject: [aspx] RE: Testing textbox for null

Try both in a response.write as a boolean condition to get the results, this

will tell you what is going on in the evaluation..

>From: "Hugh McLaughlin" <hugh@k...>
>Reply-To: "ASP+" <aspx@p...>
>To: "ASP+" <aspx@p...>
>Subject: [aspx] RE: Testing textbox for null
>Date: Sat, 22 Jun 2002 00:07:42
>
>Well actually I think OR is the right way, but I tried AND and received
>the same results.
>
> > I believe from a quick look you want to use the [AND} operator not [OR]
>because you want to fail if both condition of "" or null are met =3D)
>
>J. Scot
>IronSpire Inc.
>
>-----Original Message-----
>From: Hugh McLaughlin [mailto:hugh@k...]
>Sent: Friday, June 21, 2002 4:31 PM
>To: ASP+
>Subject: [aspx] Testing textbox for null
>
>
>Hello Everyone and thanks for your help in advance.  I am working on an
>application that builds a SQL query based on whether data has been
>entered into a text field.  An example is located at:
>
>http://www.famb.org/roster.aspx
>
>Basically, the idea is to check and see if there is data entered into
>the
>first or last anme fields and build the query accordingly.  The code is:
>
>Dim SQL As String =3D "Select * From tblMembers"
>
>If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then
>     SQL=3DSQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
>End If
>
>However, whether I enter data into the last name field or not, the WHERE
>
>clause that should be inserted only if data is present, continues to be
>inserted.  Obviously, my "If...Then" is not working properly, but I
>don't
>understand why.  Any help would be greatly appreciated.  Thanks.

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


Message #6 by "Dave Rezoski" <daverezoski@h...> on Sat, 22 Jun 2002 04:56:15 +0000
I think you need to check if LastName.Text.Length <= 0


----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP+" <aspx@p...>
To: "ASP+" <aspx@p...>
Subject: [aspx] RE: Testing textbox for null
Date: Sat, 22 Jun 2002 00:07:42

Well actually I think OR is the right way, but I tried AND and received
the same results.

 > I believe from a quick look you want to use the [AND} operator not [OR]
because you want to fail if both condition of "" or null are met =3D)

J. Scot
IronSpire Inc.

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Friday, June 21, 2002 4:31 PM
To: ASP+
Subject: [aspx] Testing textbox for null


Hello Everyone and thanks for your help in advance.  I am working on an
application that builds a SQL query based on whether data has been
entered into a text field.  An example is located at:

http://www.famb.org/roster.aspx

Basically, the idea is to check and see if there is data entered into
the
first or last anme fields and build the query accordingly.  The code is:

Dim SQL As String =3D "Select * From tblMembers"

If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then
     SQL=3DSQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

However, whether I enter data into the last name field or not, the WHERE

clause that should be inserted only if data is present, continues to be
inserted.  Obviously, my "If...Then" is not working properly, but I
don't
understand why.  Any help would be greatly appreciated.  Thanks.




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

Message #7 by "Mingkun Goh" <mangokun@h...> on Sun, 23 Jun 2002 08:46:15
Just to let you know, the value LastName.Text will not be Null no matter 
whether you put in anything in your TextBox LastName.
So it doesn't make sense to test it with IsDBNull function.


Try replacing your if else block with the following (and tell us whether 
it works):

If LastName.Text.Trim <> "" Then
    SQL = SQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If



Just to review your code:

IsDBNull(Trim(LastName.Text)) always evaluate to False
Not(IsDBNull(Trim(LastName.Text))) makes it evaluate to True

So when the code is evaluated as below:

If Trim(LastName.Text)<>"" OR True Then 
    SQL=SQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

Since the second conditions is always true, the first condition doesn't 
make a difference.
Therefore your code is always executed.



Previous message:

Hello Everyone and thanks for your help in advance.  I am working on an 
application that builds a SQL query based on whether data has been 
entered into a text field.  An example is located at:

http://www.famb.org/roster.aspx

Basically, the idea is to check and see if there is data entered into the 
first or last anme fields and build the query accordingly.  The code is:

Dim SQL As String = "Select * From tblMembers"

If Trim(LastName.Text)<>"" OR Not(IsDBNull(Trim(LastName.Text))) Then 
    SQL=SQL & " WHERE LastName LIKE '" & LastName.Text & "%'"
End If

However, whether I enter data into the last name field or not, the WHERE 
clause that should be inserted only if data is present, continues to be 
inserted.  Obviously, my "If...Then" is not working properly, but I don't 
understand why.  Any help would be greatly appreciated.  Thanks.

  Return to Index