Reputation: 90
I'm trying to update my record in database, where I'm updating the balance
column. I managed to do select and insert command but update isn't working.
Here is my code.
unit widrawMoneyPanel;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.Edit, data_module;
type
TForm8 = class(TForm)
money: TEdit;
widraw: TButton;
back: TButton;
procedure widrawClick(Sender: TObject);
procedure backClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
id: integer;
end;
var
Form8: TForm8;
currentBalance: Double;
implementation
uses customerpanel, updatecustomer;
{$R *.fmx}
procedure TForm8.backClick(Sender: TObject);
begin
form7.balance.Text := floattostr(currentBalance);
form7.show;
end;
procedure TForm8.widrawClick(Sender: TObject);
begin
DataModule1.ADOQuery1db.SQL.Text := 'SELECT * FROM customer WHERE id = :ids';
DataModule1.ADOQuery1db.Parameters.ParamByName('ids').Value := id;
try
DataModule1.ADOQuery1db.open;
currentBalance := strtofloat(DataModule1.ADOQuery1db.FieldByName('balance')
.AsString);
currentBalance := currentBalance - strtofloat(money.Text);
finally
DataModule1.ADOQuery1db.close;
end;
DataModule1.ADOQuery1.SQL.Text :=
'update customer set balance = :currentBalance where id= :ids';
DataModule1.ADOQuery1.Parameters.ParamByName('currentBalance').Value :=
currentBalance;
DataModule1.ADOQuery1.Parameters.ParamByName('ids').Value := id;
DataModule1.ADOQuery1db.ExecSQL;
end;
end.
Upvotes: 0
Views: 364
Reputation: 596407
You are assigning your UPDATE
SQL to DataModule1.ADOQuery1
, but then you are calling ExecSQL()
on DataModule1.ADOQuery1db
instead, which still has your SELECT
SQL assigned to it.
Upvotes: 4