Thursday, March 22, 2012

Meaning of error

I am getting the following message "Syntax error in query. Incomplete query clause. " referencing line 32. I don't know why, i'm using the same exact line in a statement that is working.

Help, please

Line 30: Dim Cmd as New OleDbCommand(MySQL, MyConn)
Line 31: MyConn.Open()
Line 32: objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
Line 33: ddl2.DataSource = objDR
Line 34: ddl2.DataBind()And what is the content of "MySQL"?
here's the sub routine:

Sub fillCounty(Source as Object, E as EventArgs)
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("county.mdb") & ";"
if ddl1.selectedItem.text <> "-- Choose --" then
Dim MySQL as string = "Select county from '" & ddl1.selecteditem.text & "'"
Dim Myconn as New OleDbConnection(strConn)
Dim objDR as OleDbDataReader
Dim Cmd as New OleDbCommand(MySQL, MyConn)
MyConn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
ddl2.DataSource = objDR
ddl2.DataBind()
'ddl2.items.insert(0,"-- Choose --")
end if
My recommendation would be to get rid of the single quotes in your SQL statement. You dont usually need them when specifing the table name, only field names. Try:

"SELECT country from " & ddl1.SelectedItem.Value
The way this is written, if there is no selected item, then your query will read "Select country from ''" and nothing else. Are you sure you don't mean to write:

"Select country From countries WHERE country = mumble"? Or is there a table for each item in your dropdown list?
Yes Jim, there is a table for each item in the ddl. And to answer Blade, I removed the single quotes - and left the double quotes, and now it's working.

Thanks for your help.

Since I'm still learning, I'm sure I'll be back :)

0 comments:

Post a Comment