Avatar of marioway
marioway
 asked on

TQuery locate problem

Hi, I have another problem

I run IBQuery6 -> select * from Bedrijsvorm

then

procedure TAdministratie.ComboBox1Exit(Sender: TObject);
var A: string;
begin
with Datamodule1 do begin
 if Trim(ComboBox1.Text) = '' then begin
  ShowMessage('Veld bedrijfsvorm MOET worden ingevuld !');
  ComboBox1.SetFocus;
  Exit;
 end
 else
  begin
   A:= Trim(ComboBox1.Text);
   if not IBQuery2.Locate('BEDRIJFSVORMEN', A, [])then begin
      IBQuery5.Close;
      IBQuery5.SQL.Clear;
      IBQuery5.SQL.Add('Insert INTO BEDRIJFSVORM (BEDRIJFSVORMEN) Values(:A)');
       IBQuery5.Params[0].AsString:= A ;
      IBQuery5.ExecSQL;
   end
    else
     begin
      Exit;
     end;
  end;
end;
end;

When I run the program, and exit the combobox, a locate is performed inside IBQuery6

When it does not find the value, run IBQuery5 to insert the value into bedrijfsvorm, else
Exit . The result is that I get an error (primary key violation), instead of exiting without trying to insert...

problem ?

thx
Mario
DelphiDatabases

Avatar of undefined
Last Comment
marioway

8/22/2022 - Mon
Ferruccio Accalai

Are you sure about the case of A?
I'd use  
if not IBQuery2.Locate('BEDRIJFSVORMEN', A, [locaseinsensitive])then begin
It's a bit difficult find a right answer without knowing the structure of the table when you're trying to insert that value
ASKER CERTIFIED SOLUTION
Geert G

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
Geert, thx a lot; what would I do without you guys ... I'm creating a client/server version of my stand-alone program from scratch. Not so easy, but I'm learning fast. I'm gone a have a look at that rdb$databse thing ; seems very important ...

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