....hmmm....
Do you want something like this?
following example...
I love this way of searching my tables of dbs... actually i was thinking put that code as snippet - for helping other users create a better search for their databases... Search with LIKE and "AND" is favour for all !
Add a view to layout: searchtextfield (b4xfloattextfield) - Generate member..., also if you want it more analytic add a button (name it btnsearch ...swiftbutton) too..
'add those at class_globals:
Dim SQLsearch As String = ""
Dim SQLtable As String ' the table you will show/search...
Dim SQLargs As List 'the args can be the all the columns as you can see in this example... auto-creating....
Dim sql1 As String ' here can be the column/fields of table you wanna show for example: id, customername, telephone, email
Private Sub searchtext_EnterPressed
searchtext.TextField.SelectAll
btnsearch_Click
End Sub
Private Sub btnsearch_Click
If searchtext.Text.ToLowerCase.Trim.Length>0 Then
Dim searchtocolumns() As String = Regex.Split(" ",searchtext.Text.ToUpperCase) '...i like uppercase all letters... i am doing that when writting to db too... especially at sqlite databases... because of limitations they have...
Dim newargs As String
Dim sb2 As StringBuilder
sb2.Initialize
SQLargs.Clear
Dim rs As ResultSet = datadb.ExecQuery("SELECT " & sql1 & " FROM " & SQLtable & " LIMIT 1")
For I = 0 To searchtocolumns.Length-1
sb2.Append("(")
For K = 0 To rs.ColumnCount-1
sb2.append("upper(").Append(rs.GetColumnName(K)).Append(")").Append(" LIKE ?")
SQLargs.Add("%" & searchtocolumns(I).ToUpperCase & "%")
If K<rs.ColumnCount-1 Then
sb2.Append(" OR ")
End If
Next
sb2.Append(")")
If I<searchtocolumns.Length-1 Then
sb2.Append(" AND ")
End If
Next
newargs=sb2.ToString
rs.CLOSE
B4XTable1.BuildQuery(False)
SQLsearch="SELECT " & sql1 & " FROM "& SQLtable & " WHERE " & newargs
LoadData 'a sub that you will load all values of database you want to a b4xtable - there are many examples.... using sqlsearch... ofcourse there are many other ways....
Else
' ...here you can show all your records...
End If
End Sub
How it works in runtime... when user writing for example two words: JAMES HOTMAIL --> this will show all rows have fields containing JAMES
and HOTMAIL.. you can change to
OR by placing a swith or selecting or by default... if the user give 3 words or 4 words... will automatically create different
sqlargs...
Hope it helps... ofcourse before use this example you must search and know how to show an sqlite (or mysql, ms sql table) to b4xtable...
ps: datadb is an SQL... sqlite/mssql/mysql already loaded/initialized...