Topic: any SQL Querty to select the last entry?

Hey guys, i want to use an expression to force a combo box to automaticly choose the last sql query after adding one (of course)

Here's the scenario:

I have a combo box that are linked in a cascate to other combo boxes, they are: Type, Brand and Model.
imagine that i add a new model , so... i select the type... brand... and then i click on the "PLUS" button to add a new model.
As soon as i hit the save button, i can then use on after click to call for an sql expression to find the last entry on sql and define combo box model to it's last dbitem that was just insterted.

Is this possible?

Re: any SQL Querty to select the last entry?

Hello.


Check it out

Form1.ComboBoxModel.dbItemID := Last_Insert_id;
Dmitry.

Re: any SQL Querty to select the last entry?

Funny thing, i have 3 combo boxes on my form, they are all linked together in a cascate.
Every time i added a new item i was unable to select the new item on the cascated combo box without having to deselect it and select the first combo box again...
so... i added this to the code and it solved my problem:

frmassistencia.cbtipo.DroppedDown := true;
frmassistencia.cbtipo.DroppedDown := false;

lol

Re: any SQL Querty to select the last entry?

forget the droppeddown thing,
last_insert_id breaks the following combobox ,
Eg:

I have 3 combo boxes

CB1
CB2 (parent CB1)
and CB3 (partent CB2)

As soon as i select cb2 on last id, cb3 show's every single id on the sql table, meaning that i can choose the wrong id with this bug.

help?

Re: any SQL Querty to select the last entry?

i am sorry, dbupdate was destroying the connection
But without dbupdate last_insert_id doesn't work

Re: any SQL Querty to select the last entry?

i manage to get this working if i do this:


frmassistencia.cbmarca.ItemsChecked[0] := true;
   frmassistencia.cbmodelo.dbItemID := Last_insert_id;

(CBMARCA is the partent CB for CBMODELO)

it has a weird side effect tough, it pauses for a second while it checks sql database.

Re: any SQL Querty to select the last entry?

Hello Vasco,


I come after the battle, but I still think this info can be usefull.


I don't like the last_insert_id, because it will get you the last inserted ID whatever the table.


Consider this : you insert a new product in your product table, and you want it's ID in your combobox. But just after inserting the product, you have a second query inserting the price of the product in another table. Which ID will you get in your combobox ? Yes, the ID of the price record in the price table, and that's not what you want.


Other example : instead of inserting a new product, you update an existing one. Last_insert_id will get you the last inserted ID whatever the table, when what you want is the ID of the updated record.


You only should use last_insert_id if what you use it for occurs immediately after the insertion, and nothing else in between.


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor