Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 23
  1. #1
    Join Date
    Nov 2006
    Posts
    24

    SQLite to DataGrid

    I am trying to load the contents of a SQLite database into the datagrid. I have been all over the forums and can't find any examples here or at IcyNorth. Can someone show me how to do this? I need the grid to update anytime the database updates.

  2. #2
    Join Date
    May 2005
    Posts
    1,115
    LOL, dude, there are no database events in SQLite that you could hook to. Even if there were, you wouldn't have a component in APMS to connect to that hook (like the one that comes with Direct Oracle Access package for Delphi).

    If you want to load a SQLite.QueryToTable result to a grid or datagrid, each time you enter a page, you have to:
    1. prepare a grid/datagrid from scratch (column names, sizes, etc...) using actions, since it's a jerky component that doesn't keep it's state when you change pages,
    2. run a SQLite.QueryToTable action to fill the grid,
    3. eventually select the last item that was selected in the grid before you left the current page (if you make some mechanism to remember this).

    Here is an example for the query:
    Code:
    local count, row
    local cus = SQLite.QueryToTable(db, "SELECT * FROM customers ORDER BY name LIMIT 1000;")
    DataGrid.DeleteNonFixedRows("dg1", true);
    if cus and cus.Rows>0 then
    	for count=1, izm.Rows do
    		row = DataGrid.InsertRow("dg1", false);
    		DataGrid.SetCellText("dg1", row, 0, id, false)
    		DataGrid.SetCellText("dg1", row, 1, name, false)
    		-- other columns you need
    	end
    end
    DataGrid.Refresh("dg1")
    P.S. "dg1" is a name od the grid/datagrid. Of course, you have to prepare grid before you fill it.
    Last edited by bule; 08-01-2008 at 12:10 PM.
    Never know what life is gonna throw at you.
    (Based on a true story.)

  3. #3
    Join Date
    Nov 2006
    Posts
    24
    Wow, it's almost not worth it..............
    I guess it's going to be more economical to use a couple listboxes instead and make it look "gridlike". I guess theres no way to load it to a HTML file that the user can make selections in and edit any of the fields is there?

  4. #4
    Join Date
    May 2005
    Posts
    1,115
    Well, the grid is still better than a one column limited listbox or multiple listboxes simulating a grid. The grid looks like an old Buick, but what can do.

    Editable HTML? LOL, it's doable and you could do some beautiful editable tables with it, but your HTML, JavaScript and Lua code would be as long as Mount Everest. Actually, longer!!!
    Never know what life is gonna throw at you.
    (Based on a true story.)

  5. #5
    Join Date
    Nov 2006
    Posts
    24
    Yeah I agree. I went over the other options and came back to the grid. Though it's pain it's still the shortest distance between two points and looks the cleanest. Thanks Bule.

  6. #6
    Join Date
    May 2006
    Posts
    5,380
    The grid looks like an old Buick
    ha ha ha, yeah it dose that

    iv just been playing with an ocx i made, just a listicon on a borderless page, set the ams page to non movable and set the listview window position and i have a usable multi column listbox embedded into/on top of the page, can even catch mouse clicks, i may release it later
    Open your eyes to Narcissism, Don't let her destroy your life!!

  7. #7
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    I made this example when Brett and I colaborated on the DataGrid. Here it is, modified to work with the IR Grid. The project allows you to open a SQLite database. The tables are listed on one side, once you select a table, the data is bound to the second grid. You can edit the data in the grid, and the results will be saved once you leave the cell.
    Attached Files

  8. #8
    Join Date
    May 2006
    Posts
    5,380
    i was toying with the idea of making a generic grid on my projects main page that would contain various info from sections of the app at the click of a button, originaly i decided not to bother just yet as i couldent be botherd to reset the grid every time (hopeing for a replacment )

    but your "BindGrid" function takes care of that.

    a very useful/helpful example worm, thanks

    btw, i dident know you had a hand in on the grid, i should have gussed really tho, some of the functionms have a *worm* feel to them, lol
    Open your eyes to Narcissism, Don't let her destroy your life!!

  9. #9
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    in that post, colaborating's definition would be...

    - Brett being a nice guy and letting me ride on his coat-tail

  10. #10
    Join Date
    Nov 2006
    Posts
    24
    Thanks for saving the day again Worm. That was exactly what I needed. Not only does it fix the problem at hand it opens up a huge array of other ideas.............so much programming so little time...............

  11. #11
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Great example Worm, Thanks!

  12. #12
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Sure thing...

    I'm sittin' in a hotel in Dallas, it was nice to have something to kill some of the down time with.

  13. #13
    Join Date
    Nov 2006
    Posts
    24
    So along the same lines, stemming off of this. Could the data be loaded into pre-existing columns without changing the heading text in the fixed rows? And could the listbox be removed so the database with a single table could be opened and edited in the grid? Just in case you needed to kill more time.

    That may work better in my current project. I can't seem to get it to keep the column header text in place without screwing up the order of everything.

  14. #14
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    You can pass any query you want to the BindGrid function, just be sure to add RowID as the first column. SQLite has a "hidden" column named that that is more a less a rowid.

    If you want different column names, use an alias in your select statement.

    Here's an example... you'll need to have the database (Northwind) opened first.
    Code:
    		nCursor = SetCursor(32514)
    		BindGrid(dbHandle, "grdQueryResult", "Select RowID, OrderID as OrderNum, CustomerID as CustomCustomerID, RequiredDate as DifferentName from Orders");
    		ReturnCursor(nCursor)
    		Grid.AutoSizeColumns("grdQueryResult", GVS_BOTH, true)
    		Grid.SetGridLines("grdQueryResult", true, true)

  15. #15
    Join Date
    Aug 2004
    Location
    Somewhere in Texas, USA
    Posts
    417
    Dallas!...My neighborhood.

    Try the mexican food while your here.

    We have the BEST in the country.

Similar Threads

  1. SQLite database in MEMORY only!
    By Intrigued in forum AutoPlay Media Studio 5.0
    Replies: 5
    Last Post: 10-23-2009, 07:49 PM
  2. How to convert access database to sqlite database.
    By sside in forum AutoPlay Media Studio 5.0
    Replies: 2
    Last Post: 07-22-2008, 07:44 PM
  3. SQLite version - 2x or 3x
    By sferguson in forum AutoPlay Media Studio 7.5
    Replies: 7
    Last Post: 02-02-2008, 10:09 AM
  4. Datagrid example requested
    By sue in forum AutoPlay Media Studio 6.0
    Replies: 5
    Last Post: 05-18-2006, 01:06 PM
  5. Spotlight: SQLite Actions Plugin
    By Desmond in forum AutoPlay Media Studio 5.0
    Replies: 0
    Last Post: 03-12-2004, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts