Problem inserting data into firebird table

marioway
marioway used Ask the Experts™
on
Hi, I have a problem inserting data into Firebird tables.

- Connecting to database: no problem
- Using TIBDatabase; TIBTransaction, TIBQuery
- Running first TIBQuery on table 'STRAAT'  1 field with Unique index 'STRATEN'
   
  IBQuery1.Close;              //Straat
  IBQuery1.Prepare;
  IBQuery1.Open;
  IBQuery1.First;
   for i:= 0 to IBQuery1.RecordCount-1 do begin
    ComboBox2.Items.Add(IBQuery1Straten.Value);
    IBQuery1.Next;
   end;

Then by exit ComboBox2

procedure TAdministratie.ComboBox2Exit(Sender: TObject);
var A: string;
begin
with Datamodule1 do begin
 if Trim(ComboBox2.Text) = '' then begin
  Exit;
 end
  else
   begin
    A:= Trim(ComboBox2.Text);
    if not IBQuery1.Locate('Straten', Trim(ComboBox2.Text), [])then begin
      IBQuery5.Close;
      IBQuery5.SQL.Clear;
      IBQuery5.SQL.Add('Insert INTO STRAAT(STRATEN) Values(:A)');
      IBQuery5.Prepare;
      IBQuery5.ExecSQL;
    end
     else
      begin
       Exit;
      end;
  end;
end;
end;

Result is that in the field of the table, data: NULL, instead of the naam of ComboBox2

what might be the problem here ? I know something about SQL-programming, but connot get this right. Can anyone help me on this

thx
Mario
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
A:= Trim(ComboBox2.Text);
...
      IBQuery5.SQL.Add('Insert INTO STRAAT(STRATEN) Values(:A)');

That is not enough to insert the parameter. I don't have it on hand, so you should do some Googling, but it may be something like IBQuery5.ParamByName('A').AsString := A;

Even then, that may not work -- I think Firebird parameters are declared differently from :A, it may be @A or $A or something -- again, you're going to have to Google.

I hope this helps

Author

Commented:
Hi rfwoolf, I tried this

    A:= Trim(ComboBox2.Text);
    if not IBQuery1.Locate('Straten', Trim(ComboBox2.Text), [])then begin
      IBQuery5.Close;
      IBQuery5.SQL.Clear;
      IBQuery5.SQL.Add('Insert INTO STRAAT(STRATEN) Values(:A)');
       IBQuery5.Params[0].AsString:= A;
      IBQuery5.ExecSQL;

and it works

thx a lot
Mario

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial