Lazarus
Programming => Databases => Topic started by: kakarotv5 on November 04, 2007, 04:46:54 pm
-
I use SQLite.
I want insert values into the database fields but I do not want use a TDBgrid control or similar Data Controls.
I want to insert values by means of code.
How I do it?
Thanks.
-
I have found the solution:
dsTest.ExecSQL('INSERT INTO TableName(Field1,Field2,...,Fieldn) values'+'('''+Edit1.Text+''','''+Edit2.Text+''','''+ ... +Editn.Text+''')');
dsTest.RefetchData;
-
just the info I was looking for :)
after using sql prepare statements to use the database name needed, I was then able to use the insert command shown here
-
You can also do:
dsTest.Append;
dsText.FieldByName('Field1').AsString := Edit1.Text;
dsText.FieldByName('Field2').AsString := Edit2.Text;
etc
dsTest.Post;
ApplyUpdates;
Some notes:
- in this way is necessary to have a AutoInc field or the PrimaryKey must be set to the proper field
- ApplyUpdates can be applied later, eg when the form closes etc
- is possible to set SaveOnClose and SaveOnRefetch to true that will call applyupdates in the necessary places