Forum > Database
problen updating lazarus / sqlite database using a dbgrid
(1/1)
steveinalabama:
Using Lazarus with sqlite3 and a dbgrid
Originally I tried using the dbnavigator buttons to edit, then types in my values, then used the navigator post button
but the updates were not done.
I tried adding apply uodates beofre the close statement I have tied to a button used to exit the progra
but it gives error message along the lines are no row is in edit or insert status.
I then added a new button names updates and using post or appl updates did not compile.
Finally I created a limited work around ... I added a second sql quary and the edit button
procedure TForm1.Button3Click(Sender: TObject); // updates button
begin
showmessage('new logic');
sqlquery2.close;
sqlquery2.SQL.clear;
sqlquery2.sql.add('update myreminders set reminder_seen = 99') ;
//applyupdates; not works
sqlquery2.execsql;
sqltransaction1.commit;
// previous attempts ... none compiled or ran
// sqlquery2.post;
// sqlquery2.applyupdates;
//sqlite3connection1.applyupdates(9);
end;
The obvious problem is that it is hard coded, does not get values from the dbgrid,
does not know the recod key so it updates all records.
All the internet help I've read have you us the query fieldbyname function or the query fields.
Totally unusable as the query has not been updated yet.
The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.
Does anybody have or know of such a program?
Thanks.
TRon:
--- Quote from: steveinalabama on September 23, 2024, 09:20:35 pm ---The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.
--- End quote ---
Instead of someone making an explicit example for you it could be more helpful having a look at one of the many examples accompanied with Lazarus or have look at the wiki. In particular this example
dseligo:
--- Quote from: steveinalabama on September 23, 2024, 09:20:35 pm ---The simplest solution would be if someone could upload a simple lazarus program using sqlite database with a dbgrid
able to update any field in the dbgrid.
--- End quote ---
Here you go.
steveinalabama:
Thank you Deseligo, for creating the zip file for me, but sorry to say I cannot run it.
It ran initially, and I wanted to put some buttons on the form, and it went downhill from there.
I tried deleting my changes but no luck.
I got ouut of Lazarus, unzipped the zip file again into a new folder. If opened the pas file in Lazarus and
it worked, thank you. But I got out of Lazarus, dent into dbbrowser and saw the 4 records I just created from
the dbgrid. The dat was there but I made no table changes in DBBrowser. I exited, went back into Lazarus
and compiled it but only an empty form appeared. I checked that the dbgrid was visible propery was set to visible, tried to
build, then compile and it fails with something like "cannot create the output EXE file. But no program was running, liust Lazarus itself.
I rebooted and started again, and still nothing appears on the form. Task manager shows nothing running except Lazarus.
I went into appdata to delete the project1.exe file but it will nt delete...says it is in use. After a reboot I was able to get into
appdata and delete project1.exe. I want into Lazarus, did a close all because it has an empty for1 and pass file.
After run without debugging, no form appears and no other programs are running... same result.
I saved the project as a different name to get around the cannot create output file, but still get a form1 with no grid on it.
I ulso changed the form name to form1b but running it still shows an empty form1.
Any suggestions on my next step?
Thank you for your help.
dseligo:
--- Quote from: steveinalabama on September 24, 2024, 05:37:15 pm ---Any suggestions on my next step?
Thank you for your help.
--- End quote ---
I am not sure I'd understood your post completely, but I'm pretty sure that there is something else going on at your end.
You are describing many issues: loss of data after restarting program, can't delete .exe, corruption of form.
What OS and version of Lazarus do you have?
Navigation
[0] Message Index