Populating the Datagrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gagsoft
Posts: 168
Joined: Sat Jun 29, 2013 7:56 pm

Populating the Datagrid

Post by gagsoft » Fri Jan 05, 2018 9:52 am

Hi Guys
I think I am missing it somewhere with this one.
Up to now I have been doing this the "monkey see monkey do" way.
I do understand the concept of connecting to a remote SQL database and creating a query "The Cursor"
The data is then by default stored in a tabbed delimited array with cr at the end of each line in a data variable.
The datagrid is then populated with the Array data.
Please correct me if I am wrong with any of the above process concepts.

Here is my code
-- Here it connects to a remote MySQL database
-- It notifies the user that the connection is made

-- connecting to the database
on mouseUp
global dbID
put revOpenDatabase(“MySQL","The IP address”,"Database Name”,”User Name","My Password") into dbID
if dbID is not a number then
answer warning "Error "&dbID
exit to top
else
-- notify the user of any errors if any
answer info "You are connected"
end if
end mouseUp

-- The query is executed and the result put into TheData variable
global dbID

set itemdelimiter to tab
-- This is a field on my stack with the query
put fld "sql1" into theQuery
put revDataFromQuery(,,dbID,theQuery) into theData

if theData contains "revdberr" then
answer warning "There is an error "&theData
exit to top
end if

set the dgText [true] of grp "datagrid1" to TheTextData & tData

At the moment the array is stored in a field called theResult on the main stack
Kindly see the attached image.
I do not get any errors but the datagrid does not get populated.

Would really appreciated it if someone could just point out any syntax errors and the process of loading the data into the datagrid.
Screen Shot 2018-01-05 at 10.49.52.png

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Populating the Datagrid

Post by Klaus » Fri Jan 05, 2018 11:37 am

Hi gagsoft,

Code: Select all

...
set the dgText[true] of grp "datagrid1" to TheTextData & tData
...
If TheTextData contains the columnnames of your datagrid and tData the data from your database,
then you need to add a nother CR to have these in a separate line:

Code: Select all

...
set the dgText[true] of grp "datagrid1" to TheTextData & CR & tData
...
Best

Klaus

gagsoft
Posts: 168
Joined: Sat Jun 29, 2013 7:56 pm

Re: Populating the Datagrid

Post by gagsoft » Fri Jan 05, 2018 12:07 pm

Hi Klaus
Thank you for your response.
I altered the code accordingly with no change in the result.
"set the dgText[true] of grp "datagrid1" to TheTextData & CR & tData"
It does not populate the datagrid.

Peter G

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Populating the Datagrid

Post by Klaus » Fri Jan 05, 2018 12:25 pm

Hi Peter,

does it work if you omit TheTextData?
...
set the dgText of grp "datagrid1" to tData
## Maybe this will give some hints, butI''m not sure if the DG commands return something at all:
answer the result
...

Best

Klaus

gagsoft
Posts: 168
Joined: Sat Jun 29, 2013 7:56 pm

Re: Populating the Datagrid

Post by gagsoft » Fri Jan 05, 2018 1:52 pm

Hi Klaus
It works.....My apologies.
I realised that i was originally referring to its thedata instead of tData.

Many Thanks
Peter G

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”