Help with SQL Query

I seem to be having trouble when I perform this SQL query with this WHERE clause for selecting a value from the PartNo field. It returns a Nil even though the PartNo for the chosen row is stored in the database under the field. Any input would be appreciated.

For example, the part number I was trying was NXT-10033 which has two instances in the database table.

sql = "SELECT * FROM SKU WHERE PartNo = " + PopupMenuPartNo.SelectedRowValue

  results = App.MyDatabase.SelectSQL(sql)
Catch error As DatabaseException
  MsgBox("DB Error: " + error.Message)
End Try

If results Is Nil Then Return

PartNo appears to be text, but you did not include quotes in your SQL.

Regardless, you should use a prepared statement, and SelectSQL makes that easy. Try it this way:

sql = "SELECT * FROM SKU WHERE PartNo = ?" // Assuming SQLite

  results = _
    App.MyDatabase.SelectSQL( sql, PopupMenuPartNo.SelectedRowValue )
Catch ...

You should have gotten something in error to that effect.

1 Like

Yep, that worked perfectly. Thanks for the tip and the information going forward.