?
Solved

DropDownList Question

Posted on 2005-03-04
5
Medium Priority
?
193 Views
Last Modified: 2010-04-23
I am trying to bind a dropdownlist to some SQL code and I am receiving the following message "Operator " +" is not defined for type string and System.WebUI.Webcontrols.Listitem'

As well I am getting an error that says Name 'ColorList is not decalred'.

Can anyone assist me with these issues?

Thanks


Private Sub DrpDwnTitle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DrpDwnTitle.SelectedIndexChanged

        Dim strsql As String
        Dim connstring As String
        Dim conn As OleDbConnection
        Dim comm As OleDbCommand


        ' Create a table to store data for the DropDownList control.
        Dim dt As DataTable = New DataTable

        connstring = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source= C:\Documents and Settings\egreen\Desktop\EmployeeFinal Design.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
        strsql = "SELECT [Employees].[EmployeeID], [First_Name] & ' ' & [Last_Name] AS Name FROM Employees WHERE [Employees].[Title] Like ' " + DrpDwnTitle.SelectedItem + " ' ORDER BY [Employees].[First_Name], [Employees].[Last_Name]"
        ColorList.DataSource = dt
        ColorList.DataTextField = "Name"
        ColorList.DataValueField = "EmployeeID"

        ' Bind the data to the control.
        ColorList.DataBind()


    End Sub
0
Comment
Question by:earngreen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 13462643
Change the + operators to & operators and that should solve your problem.
0
 

Author Comment

by:earngreen
ID: 13462701
I tried changing those operators various ways with no luck.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 13463036
Well the problem is with both those operators AND with the dropdown.  You need to use the ampersand (&) and also you need to get text from the dropdown.  I don't know if the dropdown contains an object with a .ToText method?  If not you can probably use SelectedText instead of SelectedItem.  Try changing this part of your statement:

Like ' " + DrpDwnTitle.SelectedItem + " ' ORDER

To this:

Like ' " & DrpDwnTitle.SelectedText & " ' ORDER

0
 
LVL 14

Assisted Solution

by:amyhxu
amyhxu earned 1000 total points
ID: 13467220
strsql = "SELECT [Employees].[EmployeeID], [First_Name] + ' ' + [Last_Name] AS [Name] FROM Employees WHERE [Employees].[Title] Like ' " & DrpDwnTitle.SelectedItem.Text & " ' ORDER BY [Employees].[First_Name], [Employees].[Last_Name]"
0
 
LVL 14

Accepted Solution

by:
amyhxu earned 1000 total points
ID: 13467225
You must add another dropdownlist named ColorList in your designer or in code to solve the 'ColorList is not decalred' problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question