Roman, thank you for your question. I think I do learn trying to solve problems more than just reading docs or watching youtube.
This is what I did:
[code]Listbox1.DeleteAllRows
Dim sql As String
Dim ps As SQLitePreparedStatement
Dim rs As RecordSet
sql = “SELECT * FROM Clients WHERE Name LIKE ? AND Surname LIKE ? AND ID LIKE ?”
ps = db.Prepare(sql)
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
If TFName.Text <> “” Then
ps.Bind(0, TFName.Text)
Else
ps.Bind(0, “%”)
End if
ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
If TFSurname.Text <> “” Then
ps.Bind(1, TFSurname.Text)
Else
ps.Bind(1, “%”)
End if
ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
If TFid.Text <> “” Then
ps.Bind(2, TFid.Text)
Else
ps.Bind(2, “%”)
End if
rs = ps.SQLSelect
If rs <> Nil and rs.RecordCount > 0 Then
do until rs.EOF
Listbox1.AddRow (rs.Field(“Name”).StringValue,rs.Field(“Surname”).StringValue,rs.Field(“ID”).StringValue)
rs.MoveNext
loop
end if
rs = Nil[/code]
From my test, this code works like this:
- if all 3 are empty, it will list all records in database
- if 1, 2 or 3 have info, it will use that to search
By using LIKE and not = I can get results searching for ID “tt3” when the database contains “TT3”, or find Jon/JON when the textfield contains “jon”
I’m learning about PreparedStatements and why to use them.
Remember, I’m a newbie but I hope this code helps. If you have any comments or fixes, they are welcome.