1 (edited by v_pozidis 2014-09-15 13:09:02)

Topic: pressing one button for two records

I have two tables

I would that with pressing one button to insert record in two different tables.
example
pressing a button i would add record
edit1.text = table1.name
edit2.text= table2.lastname

how can I do it?

Re: pressing one button for two records

You can do it using by script, example

SQLExecute ('INSERT INTO table1 (field1, field2) VALUES ("value1", "value2")');
SQLExecute ('INSERT INTO table2 (field1, field2) VALUES ("value1", "value2")');
Dmitry.

Re: pressing one button for two records

Table1 name is omades
Tbale2 name is omadesA

the colum of table 1 is omada1
and the colum of table 2 is omada2

so the when i write in edit2.text and edit2.text something this must be stored in the follwinf colums

In table1  in the colum omada1  the value of edit1.text
and in table2  in colum omada2 the value of edit2.text

how do I write it like this below????
because thre must be an error?
SQLExecute ('INSERT INTO omada1 (omada1)  VALUES (Edit1.Text)');
SQLExecute ('INSERT INTO omadaA (omada2) VALUES (Edit2.Text)'); 

and hoh can I delete them also?

Thank you in advance

Re: pressing one button for two records

SQLExecute ('INSERT INTO omada1 (omada1)  VALUES ("'+ Form1.Edit1.Text +'")');
SQLExecute ('INSERT INTO omadaA (omada2) VALUES ("' + Form1.Edit2.Text +'")'); 

for delete

var
   idRecord: integer;
begin
   SQLExecute ('DELETE FROM omada1 WHERE id = ' + IntToStr(idRecord) +');

where idRecord it's id of record


Also you can delete records using by standart component TableGrid and button with action DELETE RECORD

Dmitry.

Re: pressing one button for two records

Thank you.
Where can I find simple codes for SQL to create scripts?

Re: pressing one button for two records

Here you can find Beginner SQL Tutorial
http://www.w3schools.com/sql/sql_intro.asp
http://beginner-sql-tutorial.com/sql.htm

Dmitry.

Re: pressing one button for two records

Thank you for your  help!!!!!!!!!

Re: pressing one button for two records

the code you have sen show an error :   expected ")"

var
   idRecord: integer;
begin
   SQLExecute ('DELETE FROM omada1 WHERE id = ' + IntToStr(idRecord) +');


When I need SQL code to include in a script do I always nee to put the command SQLExecute in the beginning ?

Re: pressing one button for two records

try this:

var
   idRecord: integer;
begin
   SQLExecute ('DELETE FROM omada1 WHERE id = ' + IntToStr(idRecord) );

If you need SQL query, you should use function SQLExecute('Here SQL query');

Dmitry.

Re: pressing one button for two records

It's my mistake.
What I want to do is to delete a record choosinbg it from a talegrid.
I tried it with your code you have sent but nothing happend.

Also how ca I refresh a table after adding, updating or deleting a record?
- How can I execute pressing a button the Notepad or another program?

Thank you again for your help.

Re: pressing one button for two records

v_pozidis

for delete selected record from TableGrid:

SQLExecute ('DELETE FROM tablename WHERE id = ' + IntToStr(Form1.TableGrid1.dbItemId) );

for update TableGrid

Form1.TableGrid1.dbUpdate;

for execute program

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
   OpenFile('notepad.exe');
end;
Dmitry.

Re: pressing one button for two records

Thank 's again for your help,
and a last question

How can I edit a record by scripting?
I have read the help file you have send but I can not translate it correct.
What I want to do is  when I choose from a TableGrid the Record and I like to change it,

Re: pressing one button for two records

SQLExecute ('UPDATE tablename SET field1="data1", field2="data2"  WHERE id = ' + IntToStr(Form1.TableGrid.dbItemID));
Dmitry.