?
Solved

DropDownList Question

Posted on 2005-03-04
5
Medium Priority
?
194 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
  • 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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

621 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