Andromo - Start Making Apps - Free Signup

Announcement

Collapse
No announcement yet.

Mysql rows to Grid Object

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mysql rows to Grid Object

    Hello, i have this question, how can i show table rows (mysql) in the Grid object, and if make any change in the Grid it updates on the BD.

    (i fail english -- i'm peruvian )

    Please help me!

  • #2
    Originally posted by avalonlive View Post
    how can i show table rows (mysql) in the Grid object
    Here is an example:
    Code:
    MySQLConnection, error = MySQL:connect("database", "username", "password", "localhost");
    
    if (error ~= nil) then
        Dialog.Message("LuaSQL (MySQL)", "Connection failed: (" .. error .. ")", MB_OK, MB_ICONSTOP);
    else
        MyCursor, error = MySQLConnection:execute("SELECT column1,column2,column3 FROM table");
    
        if (error == nil) then
            row = MyCursor:fetch({}, "n");
            Grid.SetColumnCount("Grid1", 3);
            Grid.SetRowCount("Grid1", MyCursor:numrows() + 1); -- reserve one extra line for column header
    
            -- show headers in grid
            Grid.SetCellText("Grid1", 0, 0, "column1", false);
            Grid.SetCellText("Grid1", 0, 1, "column2", false);
            Grid.SetCellText("Grid1", 0, 2, "column3", false);
    
            -- show data in grid
            i = 1;
            while row do
                Grid.SetCellText("Grid1", i, 0, row[1], false);
                Grid.SetCellText("Grid1", i, 1, row[2], false);
                Grid.SetCellText("Grid1", i, 2, row[3], false);
                row = MyCursor:fetch({}, "n");
                i = i + 1;
            end
    
            Grid.Refresh("Grid1");
            Grid.AutoSize("Grid1", GVS_BOTH, true);
        else
            Dialog.Message("LuaSQL (MySQL)", "Execution failed: (" .. error .. ")", MB_OK, MB_ICONSTOP);
        end
    
        -- close cursor and connection
        if not MyCursor:close() then
            Dialog.Message("LuaSQL (MySQL)", "Could not close cursor", MB_OK, MB_ICONSTOP);
        elseif not MySQLConnection:close() then
            Dialog.Message("LuaSQL (MySQL)", "Could not close connection", MB_OK, MB_ICONSTOP);
        end
    end
    and if make any change in the Grid it updates on the BD.
    You have to write a proper script in the On Cell Changed event, so a change in a cell causes an UPDATE query in the database.

    Ulrich

    Comment


    • #3
      Oh, thank you so much! its so usefull

      Comment

      Working...
      X