Thursday, March 22, 2012

meaning of syntax error

I keep getting this error "Syntax error (missing operator) in query expression 'County = xxx')" when running the following code. I have already declared the strConn earlier.

Help is appreciated :)

Sub fillCounty(Source as Object, E as EventArgs)
Dim myDataSet as New DataSet
Dim MySQL as string = "Select * from " & ddl1.selecteditem.value & " WHERE County = " & ddl2.selecteditem.text & ""
Dim Myconn as New OleDbConnection(strConn)
MyConn.Open()
Dim myOleDbAdapter as New OleDbDataAdapter(MySQL, MyConn)
myOleDbAdapter.Fill(myDataSet, "ddl2.selecteditem.text")
repeater1.DataSource=myDataSet.Tables("ddl2.selecteditem.text")
repeater1.DataBind()
stateCountyPanel.visible="false"
countyPanel.visible="true"
End SubPresumably your County field contains character data, so your comparison value should be enclosed in single or double quotes (as appropriate for your database).

For example:


Dim MySQL as string = "Select * from " & ddl1.selecteditem.value & " WHERE County = '" & ddl2.selecteditem.text & "'"

Terri
your sql statement might cause error tries this:

Dim MySQL as string="SELECT * FROM " ddl1.selectedItem.value " WHERE County='" & ddl2.selectedItem.Value & "'"
Thanks Terri and wongz - you were both right. Something as simple as a single quote - arrggghhh!!!!!

0 comments:

Post a Comment