Var f As New FolderItem
Var db As New SQLiteDatabase
// Get the db located in the Desktop, named Products.sqlite
f = SpecialFolder.Desktop.Child("Products.sqlite")
// Assign the file to the SQLiteDatabase Class
db.DatabaseFile = f
Try
// Connect to it
db.Connect
System.DebugLog "DB connected !"
Catch e As DatabaseException
MessageBox(e.Message)
End Try
// Now, the read from the db / display in the ListBox (LB) process
Var rowsFound As RowSet
Var Loop_Idx As Integer
Try
rowsFound = db.SelectSQL("SELECT * FROM List_Data") // Use your db TABLE name
For Each row As DatabaseRow In rowsFound
// Set the ListBox number of Columns
If LB.ColumnCount <> Row.ColumnCount Then
LB.ColumnCount = Row.ColumnCount - 1 // Skip the Row ID
End If
LB.AddRow ""
For Loop_Idx = 0 To row.ColumnCount - 1
LB.CellTextAt(LB.LastAddedRowIndex, Loop_Idx) = row.ColumnAt(Loop_Idx).StringValue
Next
Next
rowsFound.Close
Catch error As DatabaseException
MessageBox("Error: " + error.Message)
End Try
I changed the way the number of columns (ListBox) is set to avoid showing the RowID (provided it is in the last Column); and it is now set automatically (depends on the number of columns in the database)…
Hi Emile, thanks for the response, The way you showed above is how I’m currently doing it, but looking at the docs for the dbkit it looks as if this and other things like adding/editing and deleting records can be achieved with less coding, and (in my case) more reliability. It may be that I’ve misunderstood the purpose of the dbkit or expecting to much from it but I was hoping it would simply things.
There is no specific reliability lack in the shared code not better reliability (IMHO) elsewhere.
The code I shared was rough and done using the documentation.
You can create the TABLEs too using this kind of code.
You can also crate your own utility (import / export / Add Column / Delete Column, etc.) with this kind of code.
At last, some people find that using a specialized application (one they do not wrote) will be better; the only good thing is… the time they do not takes to develop their own solution. The downside is… they do not have the inside knowledge and must later rely on these external utilities.
I’ve resolved this by modifying SearchField|Methods|Search to include an ‘if’ statement for each affected table. For example:
If searchValue.IsEmpty Then
if table = "clients" then
SQL = "SELECT * FROM clients ORDER BY company"
End
if table = "clientshistory" then
selectedClientID = WebPageCRM.ListBoxClients.CellTextAt(WebPageCRM.ListBoxClients.SelectedRowIndex, 0).StringValue
SQL = "SELECT * FROM clienthistory where clientid = " + selectedClientID + " ORDER BY datecreated"
End
rs = Connector.Connection.SelectSQL(SQL)