This script connects to the database and displays data in a datagrid
sorry for my English

Thanks
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Welcome to this forum and specialy in the " terrible english team"sorry for my English
Code: Select all
global theDBHost
global theDBName
global theDBUser
global theDBPassword
global theDBType
global tTableMissioniAttive
local sScrollerId
## START GESTIONE DATABASE
## Connect to the database
put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
if theConnectionID is an integer then
## Query the database for data
put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1 order by ID_MISSIONE DESC" ) into theCursor
if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError
if theError is empty then
## The cursor was successfully converted to an array.
## Assign it to the data grid.
## from the database cursor will appear in the matching columns
## in the data grid.
set the dgData of group "DataGridOne" to theDataGridArray
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase theConnectionID
else
answer "Error connecting to the database:" && theConnectionID & "."
end if
end mouseUp
.......
Everyone in this forum can remember this experienceI have difficulty with your suggestion
Code: Select all
-- Btn script
on mouseUp
DoMajDB
end mouseUp
-- Btn script end
--Card or stack script
on DoMajDB
global theDBHost
global theDBName
global theDBUser
global theDBPassword
global theDBType
global tTableMissioniAttive
local sScrollerId
## START GESTIONE DATABASE
## Connect to the database
put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
if theConnectionID is an integer then
## Query the database for data
put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1 order by ID_MISSIONE DESC" ) into theCursor
if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError
if theError is empty then
## The cursor was successfully converted to an array.
## Assign it to the data grid.
## from the database cursor will appear in the matching columns
## in the data grid.
set the dgData of group "DataGridOne" to theDataGridArray
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase theConnectionID
else
answer "Error connecting to the database:" && theConnectionID & "."
end if
--Added jmb 051111
if DoMajDB is not in the pendingMessages then
send DoMajDB to me in 1000 milliseconds
end if
--Added jmb 051111 end
end DoMajDB
--Added jmb 051111
on ExitNajDB
repeat for each line aLine in the pendingMessages
if aLine contains "DoMajDB" then
cancel item 1 of aLine
end if
end repeat
exit to top
end ExitNajDB
--Added jmb 051111 end
--Card or stack script enda
sorry for my English, I don't speak English very well, I'm Italian.Everyone in this forum can remember this experience![]()
Code: Select all
on mouseUp
global theDBHost
global theDBName
global theDBUser
global theDBPassword
global theDBType
global tTableMissioniAttive
local sScrollerId
## START GESTIONE DATABASE
## Connect to the database
put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
if theConnectionID is an integer then
## Query the database for data
put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1 order by ID_MISSIONE DESC" ) into theCursor
if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
put the result into theError
if theError is empty then
## The cursor was successfully converted to an array.
## Assign it to the data grid. The 'firstname' and 'lastname' columns
## from the database cursor will appear in the matching columns
## in the data grid.
set the dgData of group "DataGridOne" to theDataGridArray
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase theConnectionID
else
answer "Error connecting to the database:" && theConnectionID & "."
end if
end mouseUp
command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i
local theFields
local theError
local count_verde -- imposto variabile conteggio Verdi
local count_giallo -- imposto variabile conteggio Gialli
local count_rosso -- imposto variabile conteggio Rossi
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
put 0 into i
put 0 into count_verde -- azzerro contatore
put 0 into count_giallo -- azzerro contatore
put 0 into count_rosso -- azzerro contatore
## Loop through all rows in cursor
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
## Move all fields in row into next dimension of the array
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]
end repeat
-- Conteggio i codici colore
switch pOutArrayA[i]["ID_CODICE_E"]
case "V"
add 1 to count_verde
break
case "G"
add 1 to count_giallo
break
case "R"
add 1 to count_rosso
break
end switch
revMoveToNextRecord pCursor
end repeat
-- Popolo le label sulla schermata Missioni
put "MISSIONI IN CORSO : " &i into field "Label Missioni" of card "LiveMissioni"
put "VERDI : " &count_verde into field "Label Verdi" of card "LiveMissioni"
put "GIALLI : " &count_giallo into field "Label Gialli" of card "LiveMissioni"
put "ROSSI : " &count_rosso into field "Label Rossi" of card "LiveMissioni"
## END GESTIONE DATABASE
## START GESTIONE OGGETTO SCROLLER TOUCH
## 50 è l'altezza della riga nel row template, moltiplico per il numero di missioni presenti
put i*50 into tAltezza
lock screen
set the unboundedHScroll of group "ScrollerGroup" to false
set the unboundedVScroll of group "ScrollerGroup" to true
iphoneControlCreate "scroller"
put the result into sScrollerId
-- general properties
iphoneControlSet sScrollerId, "visible", "true"
iphoneControlSet sScrollerId, "canBounce", "false"
iphoneControlSet sScrollerId, "pagingEnabled", "false"
iphoneControlSet sScrollerId, "canScrollToTop", "true"
iphoneControlSet sScrollerId, "vIndicator", "false"
iphoneControlSet sScrollerId, "contentRect", (0, 0, 320, tAltezza)
--iphoneControlSet sScrollerId, "rect", "0,62,320,412"
iphoneControlSet sScrollerId, "rect", "0,112,320,412"
unlock screen
end if
return theError
end ConvertSQLCursorToArray
end mouseUp
on scrollerDidScroll OffsetX, OffsetY
set the hScroll of group "ScrollerGroup" to OffsetX
set the vScroll of group "ScrollerGroup" to OffsetY
end scrollerDidScroll
on closeCard
if the environment is not "mobile" then
exit closeCard
end if
iphoneControlDelete sScrollerId
end closeCard
## END GESTIONE OGGETTO SCROLLER TOUCH
I see an "on closecard". Are you sur that is in the script btn ?the complete code of the button
Code: Select all
set the dgData of group "DataGridOne" to empty
Glad it is usefulit is ok!
Sorry. I can't test this part of your scriptI see the reload but not reset the information immediately
It update the array but not the fields of the dg ?It updates when I touch the screen and move the scroll on top.