Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with SQL Where Criteria 1

Status
Not open for further replies.

innmedia

Programmer
Mar 24, 2000
108
US
Hi All,

This is likely a breeze of a question, but I am still stuck in ASP Classic, and trying hard to get on the ASP.Net bandwagon.

Anyway, I have a web page with a dropdown list ...

<asp:DropDownList id="states" runat="server" AutoPostBack="True" DataTextField="ClientState" DataValueField="ClientState"></asp:DropDownList>

By the way the reason I have the text field and the data field the same is because it just retunrs a list of states found in the data. The SQL that fills this list is....

strSQL= "SELECT ClientState From tblClients Group By ClientState Order By ClientState"

That works fine. Here is the problem--when a selection is made from the list the postback is to pull client records for the selected state. I have these statements...

strSQL= "SELECT * FROM tblClients Where ClientState='" & states & "' Order By ClientLastName"
objCommand2 = New OleDbCommand(strSQL, objConnection)
objDataReader2 = objCommand2.ExecuteReader(CommandBehavior.CloseConnection)


When a state is selected The page returns this error...

Compiler Error Message: BC30452: Operator '&' is not defined for types 'String' and 'System.Web.UI.WebControls.DropDownList'.


I don't understand what is wrong with &. Is there some other concatenation operator? Is there something wrong about the value being returned from the states dropdownlist?

Thanks!
 
Hi,

Never mind, I figured it out. I needed to include .SelectedItem.Value to get the value of the drop down list, like this....

strSQL= "SELECT * FROM tblClients Where ClientState='" & states.selecteditem.value & "' Order By ClientLastName
 
innmedia - nice to see you figured it out.

Thanks for posting you answer as well as it helps if anyone else comes across a similar problem.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top