Android Question SQL WHERE statement Syntax error

Declan

Well-Known Member
Licensed User
Longtime User
I am using the following code to get the "setpoint" record from the "Zones" table of a Database.
I need to filter this on 2 fields: "ToolName" and "Zone"
The app compiles, but I get a syntax error when running the app.
B4X:
Dim MyTool As String
Dim MyZoneNum As String
Dim MySetPoint As String
MyTool = lblSetupTool.Text
MyZoneNum = MyZone.Substring(6)   
Dim Curs As Cursor
    Curs = SQL.ExecQuery2("SELECT setpoint FROM Zones WHERE ToolName = " & MyTool & " AND WHERE Zone = " & MyZoneNum & "", Array As String(Value))
Dim i As Int
For i = 0 To Curs.RowCount - 1
    Curs.Position = i
    MySetPoint = Curs.GetString("SetPoint")
Next
Curs.Close
 

sorex

Expert
Licensed User
Longtime User
I think you are confusing two things.

you either concatenate the value OR use the array method and use a ? where the value should be.


B4X:
Curs = SQL.ExecQuery("SELECT setpoint FROM Zones WHERE ToolName = '" & MyTool & "' AND  Zone = '" & MyZoneNum & "' ")

'versus

Curs = SQL.ExecQuery2("SELECT setpoint FROM Zones WHERE ToolName = ? AND  Zone = ?", Array As String(MyTool,MyzoneNum))

you also had missing single quotes for strings and double WHERE references
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
remove the second WHERE
 
Upvote 0
Top