0
votes

I want to to copy all lines of string in memo to dbgrid fields (Fields FREKUENSI_TPOKOK). I have tried the following :

procedure Tfrm_csbo.cmd_copyClick(Sender: TObject);
var
  tpokok: string;
  i: integer;
    Begin
      tbl_LLOANP.First;
      for i := 0 to Memo2.Lines.Count-1 do
      tpokok := 'UPDATE LLOANP SET FREKUENSI_TPOKOK = ' + Memo2.Lines[i];
      qr_LLOANP.Close;
      qr_LLOANP.SQL.Clear;
      qr_LLOANP.SQL.Add(tpokok);
      qr_LLOANP.ExecSQL;
    end
end;

but the result is not as i expected to be.

1

1 Answers

0
votes

If we indent your code properly then it looks like this:

tbl_LLOANP.First;
for i := 0 to Memo2.Lines.Count-1 do
  tpokok := 'UPDATE LLOANP SET FREKUENSI_TPOKOK = ' + Memo2.Lines[i];
qr_LLOANP.Close;
qr_LLOANP.SQL.Clear;
qr_LLOANP.SQL.Add(tpokok);
qr_LLOANP.ExecSQL;

So you execute a single SQL statement, rather than one per item. Perhaps you meant to write:

tbl_LLOANP.First;
for i := 0 to Memo2.Lines.Count-1 do
begin
  tpokok := 'UPDATE LLOANP SET FREKUENSI_TPOKOK = ' + Memo2.Lines[i];
  qr_LLOANP.Close;
  qr_LLOANP.SQL.Clear;
  qr_LLOANP.SQL.Add(tpokok);
  qr_LLOANP.ExecSQL;
end;

Do note that you are opening yourself up to SQL injection here. You should always use SQL parameters rather than build your own queries from user supplied data.