469,963 Members | 1,962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Sql query and drop down list

Hi all,

I have 2 dropdownlists that after selection feed the WHERE in a sql
query

SELECT * FROM tbl WHERE a = 'dropdown1' AND b = 'dropdown2'

I also want to add the selection to the dropdownlist that everything of
a and/or b is selected.

Is there some sort of character that I can put between the '' so it
selects everything?

Regards
Stijn

Sep 4 '06 #1
3 2818
A couple of suggestions:

1. Don't include the where clause if the user selects "everything" for a
and/or b.

2. Instead of using WHERE a = 'dropdown1' use like 'dropdown1' instead. If
they select "everything" use WHERE a like '%' to select everything.

<ta******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi all,

I have 2 dropdownlists that after selection feed the WHERE in a sql
query

SELECT * FROM tbl WHERE a = 'dropdown1' AND b = 'dropdown2'

I also want to add the selection to the dropdownlist that everything of
a and/or b is selected.

Is there some sort of character that I can put between the '' so it
selects everything?

Regards
Stijn

Sep 4 '06 #2
Thanks for the reply.

The % works but only partly. I have a gridview that is populated with
data according to selections made with the 2 dropdownlists. One of the
variable needs to be a varchar, no problem there. The other is an int.
Since % is a string I get an exception. Someone knows how I can work
around this without changing my database.

Regards,
Stijn
PaulR schreef:
A couple of suggestions:

1. Don't include the where clause if the user selects "everything" for a
and/or b.

2. Instead of using WHERE a = 'dropdown1' use like 'dropdown1' instead. If
they select "everything" use WHERE a like '%' to select everything.

<ta******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi all,

I have 2 dropdownlists that after selection feed the WHERE in a sql
query

SELECT * FROM tbl WHERE a = 'dropdown1' AND b = 'dropdown2'

I also want to add the selection to the dropdownlist that everything of
a and/or b is selected.

Is there some sort of character that I can put between the '' so it
selects everything?

Regards
Stijn
Sep 4 '06 #3
I personally would use option 1 I described below. And I would have the
logic to build the query in a stored procedure in the database. Allowing
SELECT access from your application is bad practice, especially if you have
not protected against SQL injection.

<ta******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Thanks for the reply.

The % works but only partly. I have a gridview that is populated with
data according to selections made with the 2 dropdownlists. One of the
variable needs to be a varchar, no problem there. The other is an int.
Since % is a string I get an exception. Someone knows how I can work
around this without changing my database.

Regards,
Stijn
PaulR schreef:
>A couple of suggestions:

1. Don't include the where clause if the user selects "everything" for a
and/or b.

2. Instead of using WHERE a = 'dropdown1' use like 'dropdown1' instead.
If
they select "everything" use WHERE a like '%' to select everything.

<ta******@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegr oups.com...
Hi all,

I have 2 dropdownlists that after selection feed the WHERE in a sql
query

SELECT * FROM tbl WHERE a = 'dropdown1' AND b = 'dropdown2'

I also want to add the selection to the dropdownlist that everything of
a and/or b is selected.

Is there some sort of character that I can put between the '' so it
selects everything?

Regards
Stijn

Sep 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Yoshitha | last post: by
1 post views Thread by pmelanso | last post: by
reply views Thread by dokidoki | last post: by
1 post views Thread by accyboy1981 | last post: by
8 posts views Thread by Ed Dror | last post: by
4 posts views Thread by TycoonUK | last post: by
3 posts views Thread by =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.