Page 1 of 1

Data Grid - how to check per column

Posted: Sat Sep 07, 2019 12:07 pm
by lemodizon
Hi Everyone,

How can i check in the column of data grid the (Birthdate) and update (Age). see the below example.

Thanks in advance.

Re: Data Grid - how to check per column

Posted: Sat Sep 07, 2019 2:18 pm
by dunbarx
What Klaus suggested, and the way I always deal with getting data into and out of a dataGrid, is to extract the entirety of the contents of the DG and then use good ol' LiveCode do its work.

You extract either with the "DGData", with yields an array, or my preference usually, the "DGText" which yields ordinary, er, text.

Once you have that, the DGText, say, you can use delimiters to manipulate the data. Tabs and returns are the usual suspects.

So just as if you were trying to dissect the contents of an Excel spreadsheet, each row is delimited by a return, and each "cell" is delimted by a tab. A repeat loop gets it all and orders it to your liking.

Craig

Re: Data Grid - how to check per column

Posted: Thu Sep 12, 2019 4:40 pm
by lemodizon
Hi Craig,

Thanks for the information. i was having a hard time in exploring data grid of livecode. Thanks for the support of this forum.

Re: Data Grid - how to check per column

Posted: Thu Sep 12, 2019 5:10 pm
by lemodizon
SqliteDb.PNG
Hi everyone,

I'm still exploring the data grid of livecode. i created a sqlite database see picture above. where i click the button check age it will automatic update the age. my problem is how can i put the updated age to my sqlite database per column. excuse me in my coding if you find it messy.

Thanks in advance.

Code: Select all

////here is the code in my checkage button
on mouseUp
   put the dgText of grp "StudentList" into tData
   set itemdel to TAB
   
   repeat for each line tLine in tData
      put item 5 of tLine into tDate
      put age(tDate) into tAge
      put  item 1 of tLine  & tab & item 2 of tLine  & tab&  item 3 of tLine  & tab&  item 4 of tLine  & tab & tDate & Tab &tAge & cr after tNewList
      
   end repeat
   
   if  item 1 of tLine is not empty then
      UpdateStudentInfo item 1 of tLine,  tAge
   else
      exit top
   end if
      
   delete char -1 of tNewList
   set the dgtext of grp "StudentList" to tNewList
end mouseUp

Code: Select all

////here is the command to update in the database

[img][/img]
command UpdateStudent pStudentID,pStudentAge
   local tSQLStatement
   global sDatabaseID
   
   repeat with y = 1 to the number of lines of tData
      put "UPDATE MyStudents SET  Age = '"&pStudentAge&"' WHERE ID = '"&pStudentID&"' " into tSQLStatement
      revExecuteSQL sDatabaseID, tSQLStatement
      
   end repeat
   
   if the result is an integer then
      answer "Age successfully UPDATED!"
   else
      answer "Sorry, there was a problem in UPDATING the information"
   end if
end UpdateStudent