Announcement

Collapse
No announcement yet.

SQLite.QueryToTable(db,sQuery)

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

  • SQLite.QueryToTable(db,sQuery)

    I am having trouble with this (as shown in accompanying code) i have used this code before and it worked no problem but this time I am having to show a decimal number, I think it is known as an integer and I am getting errors with the figure sVal (stands for value). can someone look at the code and tell me what is wrong, as I have said it worked every time with just text values. Any help appreciated.

    Code:
    nHeader = 6;
    	-- Set The Headers of The Grid
    	tTableHeader = {"Item", "Item Name", "Bought From", "Serial Number", "Price", "Date of Purchase", "Notes etc"};
    	for i=0,nHeader,1 do 
    		sHeader = tTableHeader[i+1]; -- LUA Table starts from 1 not 0, so must add 1 to i
    		Grid.SetCellText("Grid1", 0, i, sHeader, true);
    		Grid.AutoSizeColumn("Grid1", i, GVS_DEFAULT, true, true);
    	end
    -- set the header column to not select everything under it
    	Grid.SetFixedColumnSelection("Grid1", false);
    
    	-- set the item row to not select everything in the row
    	Grid.SetFixedRowSelection("Grid1", false);
    --------------------------------------------------------------------------
    
    nHeader = 7;
    
    	sQuery = "SELECT * FROM Contents";
    	tbReturn = SQLite.QueryToTable(db,sQuery);
    
    	if tbReturn then
    
    		for i=1, tbReturn.Rows do
    
    					Grid.InsertRow("Grid1", -1, true);
    					--sID = MyDecrypt(tbReturn.Data[i]["ID"]);
    					sName = MyDecrypt(tbReturn.Data[i]["Name"]);
    					sShop = MyDecrypt(tbReturn.Data[i]["Shop"]);
    					sSer = MyDecrypt(tbReturn.Data[i]["Serial"]);
    					sVal = MyDecrypt(tbReturn.Data[i]["Price"]);
    					sPur = MyDecrypt(tbReturn.Data[i]["Purchased"]);				
    					sNotes = MyDecrypt(tbReturn.Data[i]["Notes"]);
    					tData = {i,sName,sShop,sSer,sVal,sPur,sNotes};
    					
    					nColumn = 0;
    					for x=1,nHeader do
    						Grid.SetCellText("Grid1", i, nColumn, tData[x], true);
    						Grid.AutoSizeColumn("Grid1", nColumn, GVS_DEFAULT, true, true);
    						nColumn = nColumn+1;
    					end
    					
    					Grid.AutoSizeRow("Grid1", i, true, true);
    					Grid.ExpandLastColumn("Grid1", true);
    					Grid.AutoSizeRows("Grid1", true);
    
    		end -- for
    
    
    	else
    		Dialog.Message("Notice", "DB has no data", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    	end -- count table

  • #2
    What error are you getting?

    Ulrich

    Comment


    • #3
      Error: Page2-> On Show, line 37: Argument 4 must be of type string

      Stack Traceback
      1:[Page 2 -> On Show] Line 37 in Main Chunk




      Hi Ulrich, the line 37 in question is: Grid.SetCellText("Grid1", i, nColumn, tData[x], true);
      I may have the header totals wrong or something.
      Cheers John
      Last edited by John31; 08-18-2015, 11:01 PM. Reason: Addition

      Comment


      • #4
        You may need to check that MyDecrypt() is returning a valid value for the "Price" field. It is possible that the content of the field was not properly converted, and that this function returns nil.

        Ulrich

        Comment


        • #5
          Thanks Ulrich, checked everything and there was a mistake in the naming the field I had it down as "Price" and it should be named "Value". Don't get any pop up errors now but the page loads without showing the grid or any other buttons etc just the page complete with background colour and top menu bar but nothing else. I think I will start again from scratch this doesn't seem right at all . Many thanks for your help.
          Regards
          John

          Comment


          • #6
            Sorted it Ulrich, I needed to put the grid etc on a new Dialogue and not a new page. Once I transfered all the Objects from the Page2 to a new Dialogue1 everything worked great. Thanks again for your interest.
            Regards
            John

            Comment

            Working...
            X