Populating Datagrid From SQL Cursor
Posted: Sun Sep 08, 2019 10:02 am
I Want to add column headers dynamically into the datagrid and then populate it with an SQL Cursor.
The code connects to the database and creates the headers but does not populate the grid or generate any errors.
I must be missing something here.
Here is my code
Thanks
Peter G
The code connects to the database and creates the headers but does not populate the grid or generate any errors.
I must be missing something here.
Here is my code
populating the grid.global conID -- connection ID
global realPath -- where executable was started
global supress
constant sq="'"
on mouseUp
-- use a global variable to hold the connection ID so other scripts can use it
global ConID
-- set up the connection parameters - edit these to suit your database
put "sql9.jnb2.host-h.net" into tDatabaseAddress
put "gigscwsneg_db1" into tDatabaseName
put "gigscwsneg_1" into tDatabaseUser
put "Password" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
-- check if it worked and display an error message if it didn't
-- & set the connection ID global
if tResult is a number then
put tResult into ConID
answer info "Connected to the database." & cr & "Connection ID = " & ConID
else
put empty into ConID
answer error "Unable to connect to the database:" & cr & tResult
end if
end mouseUp
Any help / pointers would be appreciated.global conID -- connection ID
on mouseUp
local theCursor, temp, theFields, tSQL, pText, dList, ii
if not Connected() then exit to top
put revQueryDatabase( conID, "SELECT * FROM testtable") into theCursor
put the result into temp --for debugging
if "ERROR" is in temp then
answer "ERROR=" & the result
exit to top
end if
put theCursor into fld "rCounter" -- displays the number of lines
put revDatabaseColumnNames(theCursor) into theFields -- get field names from table
if the " revdberr" is in the result then
return "ERROR=" & the result
end if
replace "," with CR in theFields
set the dgProp["columns"] of group "myGrid" to theFields
put "SELECT * FROM testtable" into tSQL
put revdb_querylist(,,conID,tSQL) into ptext
put the result into dlist
if "revdberr" is in the result then
return "ERROR=" & the result
end if
put the number of lines in pText into fld "rCounter" -- displays the # of lines
set the dgColumnWidth["Handle"] of group "myGrid" to 100
set the dgColumnWidth["Entry"] of group "myGrid" to 160
repeat with ii = 1 to fld "rCounter"
put line ii of dlist into temp
dispatch "AddLine" to grp "myGrid" with temp
end repeat
end mouseUp
Thanks
Peter G