earngreen
asked on
DropDownList Question
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.L istitem'
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_SelectedIndexC hanged(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles DrpDwnTitle.SelectedIndexC hanged
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\Em ployeeFina l 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
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_SelectedIndexC
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\Em
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
Change the + operators to & operators and that should solve your problem.
ASKER
I tried changing those operators various ways with no luck.
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
Like ' " + DrpDwnTitle.SelectedItem + " ' ORDER
To this:
Like ' " & DrpDwnTitle.SelectedText & " ' ORDER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.