Recent

Author Topic: Can´t make a update (Firebird+Windows)  (Read 3266 times)

Ati

  • New Member
  • *
  • Posts: 41
Can´t make a update (Firebird+Windows)
« on: August 02, 2006, 10:25:10 am »
Hello,

i have a form with IBConnection,SQLQuery,SQLTransaction,DataSource and a DBGrid. With the first Button i fill the Grid with the Data´s here is the Code:
Code: [Select]
procedure TForm1.btnanzeigeClick(Sender: TObject);
begin
  dbmain.Close;
  dbmain.Open;
  if dbmain.Connected=true then
  begin
    dbmain.Connected:=false;
  end;
  dbmain.Connected:=true;
  qrmain.Close;
  qrmain.SQL.Text:='SELECT ID,Lager,Artikel,Menge_soll,Menge_Ist,Kommentar,Erfasser,Status,Datum,Uhrzeit From Korrekturen;';
  qrmain.Open;
  qrmain.Refresh;

 
end;  


With the second Button i want to change the Status from "Antrag" to "Erledigt" from the actually dataset. I found some Codesnippets and so my Code look like this:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var nr,stat:string;
begin
 nr:=qrmain.FieldByName('ID').AsString;
 showmessage(nr);
 dbmain.Close;
 dbmain.Open;
 trmain.StartTransaction;
 qrmain.Close;
 qrmain.SQL.Clear;
 qrmain.SQL.text:='UPDATE Korrekturen SET Status=:Status  where ID=:ID;';
 qrMain.params.ParamByName('Status').AsString:='Erledigt';
 qrMain.params.ParamByName('ID').AsString:=nr;
 qrmain.ExecSQL;
 trmain.commit;
 trmain.EndTransaction;

end;


But it doesn´t works.

Ati

Ati

  • New Member
  • *
  • Posts: 41
Can´t make a update (Firebird+Windows)
« Reply #1 on: August 02, 2006, 12:25:40 pm »
Oh my God i´m so stupid. The "ID" is from the type Integer. So looks the right Code:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var nr:Integer;
begin
 nr:=qrmain.FieldByName('ID').AsInteger;
 dbmain.Close;
 dbmain.Open;
 if dbmain.Connected=true then
  begin
    dbmain.Connected:=false;
  end;
 dbmain.Connected:=true;
 trmain.StartTransaction;
 qrmain.Close;
 qrmain.SQL.Clear;
 qrmain.SQL.text:='UPDATE Korrekturen SET Status=:Status  where ID=:ID;';
 qrmain.params.ParamByName('Status').AsString:='Erledigt';
 qrmain.params.ParamByName('ID').AsInteger:=nr;
 qrmain.ExecSQL;
 trmain.commit;
 trmain.EndTransaction;
 dbgrid1.Update;
 qrmain.Close;
 qrmain.SQL.Text:='SELECT ID,Lager,Artikel,Menge_soll,Menge_Ist,Kommentar,Erfasser,Status,Datum,Uhrzeit From Korrekturen;';
 qrmain.Open;
 qrmain.Refresh;

end;