
Я так понимаю надо перед добавлением удалить ту запись которую я выбрал? Что-то у меня не получается.
Form1(удаление и обновление):
- Код: Выделить всё
procedure TForm1.Button2Click(Sender: TObject);
var st:string;
begin
st:=SQLQuery1.FieldByName('Client_id').AsString;
SQLQuery1.Active:=False;
SQLQuery1.SQL.Clear;
SQLQuery1.SQL.Add('DELETE FROM CLIENTS WHERE Client_id='+st+';');
SQLQuery1.ExecSQL;
SQLTransaction1.Commit;
SQLQuery1.SQL.Text:='SELECT * FROM CLIENTS;';
SQLQuery1.Open;
end;
procedure TForm1.Button3Click(Sender: TObject);
var status:boolean;
begin
Form2.Show;
Form2.Edit1.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=1;
Form2.Edit2.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=2;
Form2.Edit3.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=3;
Form2.Edit4.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=4;
Form2.Edit5.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=5;
Form2.Edit6.Text:=DBGrid1.SelectedField.Text;
DBGrid1.SelectedIndex:=6;
end;
Form2(создание):
- Код: Выделить всё
procedure TForm2.Button1Click(Sender: TObject);
var query:TSQLQuery;
begin
if (Edit1.Text <> '') and (Edit2.Text <> '') and (Edit3.Text <> '') and (Edit4.Text <> '') and (Edit5.Text <> '') and (Edit6.Text <> '') then
begin
Form1.SQLTransaction1.Commit;
Form1.SQLQuery1.Active:=False;
query := TSQLQuery.Create(Self);
query.DataBase:=Form1.SQLite3Connection1;
query.Transaction:=Form1.SQLTransaction1;
query.SQL.Add('INSERT INTO Clients (Client_id,First_name,Last_name,Account_id,Address,Ph_number) VALUES (''' + Form2.Edit1.Text + ''',''' +Form2.Edit2.Text + ''',''' + Form2.Edit3.Text + ''',''' + Form2.Edit4.Text + ''',''' + Form2.Edit5.Text + ''',''' + Form2.Edit6.Text + ''' )');
query.ExecSQL;
query.Destroy;
Form1.SQLQuery1.Active:=true;
Form2.Close;
end
else
Form3.ShowModal;
end;