Page 1 of 1
Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 7:49 pm
by Gage
Hello,
I am using an SQLite database to populate a DataGrid with stored contact information. The DG is editable by the user, and I want to be able to update the database when the user leaves the card containing the DG.
I will be scripting the button that exits the card to send some sort of command to the DG to have it read the most current data in the DG's fields. What I need to figure out is the following:
- How to make the DG cycle through each index to get all of the information (does it automatically execute a custom handler for each index if you call the handler from an object outside of the DG?)
Thanks in advance!
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 9:19 pm
by Klaus
Hi Phil,
why not just script (outside of the datagrid):
Code: Select all
...
put the dgdata of grp "your data grid here..." into tDGArray
## now loop through all keys and do whatever you want with the values
repeat for each key tKey in tDGArray
put tDGArray[i]["Name of column 1 here..."] into tWhatever
## write tWhatever to database
## etc...
end ropeat
...
I hope I understood you correctly
Best
Klaus
Re: Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 10:33 pm
by bangkok
Gage wrote:I am using an SQLite database to populate a DataGrid with stored contact information. The DG is editable by the user, and I want to be able to update the database when the user leaves the card containing the DG.
Would it be better to update the DB... right after the user updates a cell ? Why do you want to wait the closecard message ?
Re: Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 10:51 pm
by Gage
Klaus,
Yes, that would be great. Only thing I need to figure out, then is how to make the dgData current. Does it automatically update if the user changes text in a field that the dgData populated when the DG was rendered?
Bangkok,
I am playing with multiple options. I don't really know how to do what you are suggesting, either. I have multiple text fields that would be editable by the user, so how would a script be implemented to update the database? What would the trigger be?
Thank you both for the ideas!
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 11:44 pm
by bangkok
Gage wrote:
I am playing with multiple options. I don't really know how to do what you are suggesting, either. I have multiple text fields that would be editable by the user, so how would a script be implemented to update the database? What would the trigger be?
Put in the script of your DG :
Code: Select all
on CloseFieldEditor pFieldEditor
put the dgColumn of the target into theColumnBeingEdited
put unidecode(the unicodetext of pFieldEditor, "UTF8") into theNewText
answer "You have typed : "&theNewText
--here you can put a SQL query, to update the data
--but you need to find the key, related to the record
end CloseFieldEditor
Re: Updataing Database with Values from DataGrid
Posted: Thu Jun 20, 2013 11:52 pm
by Gage
Bangkok,
So, in the script of the DG group, not in the behavior script, right?
What is the trigger to make that handler run?
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 3:31 am
by Gage
Klaus,
I tried implementing what you said, and it will work, but the part I am still getting tripped up on is getting the dgData to update when the user puts in new information into the fields. THEN I can take the dgData and do what you suggested. Do I just have to go through, row by row, and put the new contents of each field into the relevant spot in the dgData?
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 3:53 am
by Gage
...Going with a repeat loop containing the SetDataOfIndex command.
Guess I didn't really think that last question through.
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 7:47 am
by bangkok
Gage wrote:
So, in the script of the DG group, not in the behavior script, right?
What is the trigger to make that handler run?
In the DG group.
It will run when you close a cell, after having typed something inside.
Provided that your DG has the "allow text editing" property.
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 10:41 am
by Klaus
Hi Phil,
as soon as a user has entered new data, "the DGDATA" do update automatically,
so whenever you "put/get the dgdata..." they are always UP-TO-DATE
Best
Klaus
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 7:15 pm
by Gage
Bangkok,
OK, thank you. I will see if that works for me.
Klaus,
I implemented something similar to what you suggested, but after editing a field in the row of the DG, and then pushing the button outside of the DG that calls RevExecuteSQL to update my database, the dgData contained the default value.
this is how I got the array holding the dgData:
Code: Select all
repeat with x = 1 to 7
put the dgDataOfIndex[x] of group "Edit" of this card into theUpdateA[x]
end repeat
--load the code into an SQL command
--run revExecuteSQL
I'll keep playing with it, though.
Phil
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 7:24 pm
by Gage
Bangkok,
Using the script you suggested in the DG group code, nothing is triggering it. I see that it says "onCloseFieldEditor", but apparently CloseFieldEditor is not happening. I don't know what "closes" the field after I type in it... so I can't tell how to make it work.
I have not implemented any Field Editors anywhere in the behavior of the DG; I am reading up on that now.
Phil E.
Re: Updataing Database with Values from DataGrid
Posted: Fri Jun 21, 2013 9:27 pm
by bangkok
Try this stack.