Topic: Having a problem with an UPDATE statement

I would like some help on formatting a SQLExecute statement. I've tried all sorts of variations and this particular field never gets filled no matter what I try  I get a SQL error.


My current code is as below  and this throws a 'constraint error', however reworking this gives me different errors.


The current error is  UPDATE orders SET id_productSupplier = "x" WHERE id = "xx" (x and xx equals a ID number).

procedure frmOrderEntry_btnOrder_OnAfterClick (Sender: TObject);
var
    idx, dbx :string;
begin

     {last database entry ID}
    dbx := intToStr(Last_Insert_id);

    {ID of item in productsupplier}
    idx := intToStr(frmOrderEntry.grdOrder.dbItemID);

    showmessage('dbx '+ dbx + ' idx '+ idx);

     //extract productsupplier ID and insert into orders table
    sqlexecute('UPDATE orders SET id_productSupplier =  "'+dbx+'"  WHERE id = "'+idx+'"');
 
end;

idx and dbx do contain the correct record numbers.

Manually entering the SQL into SQL studio works, but then I'm not using variables in that instance.


Please help, otherwise the cat is only going to have 6 lives left, as his assistance has been of no help at all.

On a clear disk you can seek forever

Re: Having a problem with an UPDATE statement

CDB,
Try the following. I think your quotes may be your trouble.

sqlexecute('UPDATE orders SET id_productSupplier =  '+dbx+ '  WHERE id = '+idx);

3 (edited by CDB 2020-05-24 08:46:03)

Re: Having a problem with an UPDATE statement

Problem has been solved, your answer ehwagner did part of the trick, the rest was solved when I swapped the two variables around so that I was inserting the right bits in the right places.

Thanks for your help Derek and ehwagner.

On a clear disk you can seek forever