Updataing Database with Values from DataGrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Updataing Database with Values from DataGrid
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.
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
Hi Phil,
why not just script (outside of the datagrid):
I hope I understood you correctly 
Best
Klaus
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
...

Best
Klaus
Re: Updataing Database with Values from DataGrid
Would it be better to update the DB... right after the user updates a cell ? Why do you want to wait the closecard message ?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.
Re: Updataing Database with Values from DataGrid
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.
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
Put in the script of your DG :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?
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
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.
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
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.
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
...Going with a repeat loop containing the SetDataOfIndex command.
Guess I didn't really think that last question through.
Phil E.
Guess I didn't really think that last question through.
Phil E.
Re: Updataing Database with Values from DataGrid
In the DG group.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?
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
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
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
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:
I'll keep playing with it, though.
Phil
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
Phil
Re: Updataing Database with Values from DataGrid
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.
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
Try this stack.
- Attachments
-
- TEST.zip
- (4.67 KiB) Downloaded 321 times