Avatar of marioway
marioway
 asked on

Problem inserting data into firebird table

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
DelphiDatabases

Avatar of undefined
Last Comment
marioway

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
rfwoolf

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
marioway

ASKER
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23