Tough question for expert

J

jonny

I have two dropdown controls and one sql table with column 1 & 2. I
would like dropdown2 selection to be based on the selected item in
dropdown1.

For example, if dropdown1 selection is "oee" then I would like
dropdown2 to only show selection for items in the table column 2 where
column 1 has "oee" listed.

So what I am having trouble with is the connection string where I only
want to return items where equal to dropdown1 value...see my
connection string here:

Dim sql As String = "SELECT distinct column2 FROM MyTable Where
column1 = webform.dropdown1"

I think i am hung up here where I am using the actual value in
dropdown1 on webform in my sql connection string...

Please advise.
 
G

Gregory A. Beamer

I have two dropdown controls and one sql table with column 1 & 2. I
would like dropdown2 selection to be based on the selected item in
dropdown1.

For example, if dropdown1 selection is "oee" then I would like
dropdown2 to only show selection for items in the table column 2 where
column 1 has "oee" listed.

So what I am having trouble with is the connection string where I only
want to return items where equal to dropdown1 value...see my
connection string here:

Dim sql As String = "SELECT distinct column2 FROM MyTable Where
column1 = webform.dropdown1"

I think i am hung up here where I am using the actual value in
dropdown1 on webform in my sql connection string...

Please advise.

Not exactly what you are aiming at, but it can give you some ideas to
help you:
http://snurl.com/s4d5r

If you can use drop downs for each of the levels, it will do, however.
 
P

Patrice

A descriptive subject would be better...

A SQL statement knows nothing about your web page. Keep in mind that it will
be send to your database server where it will run. So it has in no way
access to the web server and even less to the intimate details of the
originating web page.

You have to feed the value taken from DropDown1.SelectedValue into your SQL
statement likely using a parametized query (see the ADO.NET doc or
http://aspnet101.com/aspnet101/tutorials.aspx?id=1). Basically the idea is
that the SQL Server will have to receive the actual value for your dropdown.
Though concatening strings could work this is not a best practice (as it
could be easy for an attaquer to alter the input string to alter the
statement SQL send to the server in an harmfull way).

As a side note this is rather just a SQL statement (a connection string is
the string that defines the *connection* information not the SQL statement
you send to a server).

--
Patrice

"jonny" <[email protected]> a écrit dans le message de groupe de
discussion :
(e-mail address removed)...
 
J

jonny

(e-mail address removed):









Not exactly what you are aiming at, but it can give you some ideas to
help you:http://snurl.com/s4d5r

If you can use drop downs for each of the levels, it will do, however.

Gregory,

Thanks for your post. I do not see the cascadingdropdown control in my
toolbox. How do I get it there?
 
J

jonny

A descriptive subject would be better...

A SQL statement knows nothing about your web page. Keep in mind that it will
be send to your database server where it will run. So it has in no way
access to the web server and even less to the intimate details of the
originating web page.

You have to feed the value taken from DropDown1.SelectedValue into your SQL
statement likely using a parametized query (see the ADO.NET doc orhttp://aspnet101.com/aspnet101/tutorials.aspx?id=1). Basically the idea is
that the SQL Server will have to receive the actual value for your dropdown.
Though concatening strings could work this is not a best practice (as it
could be easy for an attaquer to alter the input string to alter the
statement SQL send to the server in an harmfull way).

As a side note this is rather just a SQL statement (a connection string is
the string that defines the *connection* information not the SQL statement
you send to a server).

--
Patrice

"jonny" <[email protected]> a écrit dans le message de groupe de
discussion :
(e-mail address removed)...

Thanks Patrice,

But I am writing this sql query on a separate page and call it up with
the code from form where dropdown is at, otherwise this code below
would work

sql = "Select * from Employees where Lastname = '" &
ddl.selecteditem.text & "'"

However, again I am writing the query on another page so it would need
to be something like...

sql = "Select * from Employees where Lastname = '" &
FORM1.ddl.selecteditem.text & "'"

But the problem is I do not know how to get this page I am writing the
query on to recognize the web form where i have the dropdown control.
Please advise.
 
P

Patrice

sql = "Select * from Employees where Lastname = '" &
ddl.selecteditem.text & "'"

Ok this is not what in your shown in your first.
However, again I am writing the query on another page so it would need
to be something like...

You never mentioned this in your first post.
But the problem is I do not know how to get this page I am writing the
query on to recognize the web form where i have the dropdown control.

Ah, this is not the problem In thought you had. It would be then :

http://msdn.microsoft.com/en-us/library/6c3yckfw(VS.80).aspx (How to: Pass
Values Between ASP.NET Web Pages )
 
P

Patrice

However, again I am writing the query on another page so it would need
to be something like...

As a side note you may want to double check posting to another page is your
best option. It could be more natural to post to the same page plus if you
are still on the two related dropdown issue if the user change his mind it
could be easier for him to just reselected another value in the first
dropdown rather than having to go back to the first page (if you are no more
in this scenerio you may want to iopen a new thread so that we don't believe
this is still what you are trying to do).

You also have an ASP.NET control that allows to create a wizard like process
using a single page (with next/previous/finish buttons depending on the
current step).
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top