Tough question for expert

  • Thread starter Thread starter jonny
  • Start date Start date
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.
 
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.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
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)...
 
If you mean something like this :

http://asp.net.do/test/DependListBoxes.aspx

I can post the code...

Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en españolhttp://asp.net.do/foros/forums/
=====================================================

Yes that is what I want to do only using dropdowns rather than
listbox. Yes please post code I appreciate your help with this
struggle.
 
(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 A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog:http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:http://www.crazycancertour.com

*******************************************
|      Think outside the box!             |
*******************************************

Gregory,

Thanks for your post. I do not see the cascadingdropdown control in my
toolbox. How do I get it there?
 
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.
 
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 )
 
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).
 
Thanks for your post. I do not see the cascadingdropdown control in my
toolbox. How do I get it there?


Download the AASP.NET AJAX toolkit from www.asp.net/ajax

peace and grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top