TSQLQuery move to inserted record? lazarus / 16-Databases ---------------------------------------------------------------------- panoss · 2014-12-04 18:00 After a new record insert, how can we move the dataset to the new record? ---------------------------------------------------------------------- JZS · 2014-12-05 01:58 Identify your database please. And, are you using the default SQLQuery or Other? Can not give direct answer without the above. Anyway, use http://wiki.freepascal.org/locate function and pass your ID column and the LastInsertedID from your query component. SqlQuery1.Locate('TableID', PutLastInsertedID, []); PutLastInsertedID = You get the last inserted ID JIC if you do not have ID then you need to use another column that will result in a unique row. ---------------------------------------------------------------------- fpcoder · 2014-12-05 04:17 A call to Insert puts the query on the position of the new record. The record will be empty and you then assign some values and save the record. If the record is appended, you could call Query.Last after commiting or refreshing the query. Quote from: panoss on December 04, 2014, 07:00:38 pmAfter a new record insert, how can we move the dataset to the new record? ---------------------------------------------------------------------- panoss · 2014-12-05 09:59 Quote from: JZS on December 05, 2014, 02:58:07 amIdentify your database please. And, are you using the default SQLQuery or Other? Can not give direct answer without the above. Anyway, use http://wiki.freepascal.org/locate function and pass your ID column and the LastInsertedID from your query component. SqlQuery1.Locate('TableID', PutLastInsertedID, []); PutLastInsertedID = You get the last inserted ID JIC if you do not have ID then you need to use another column that will result in a unique row. It's SQLite3. I 'm using the defaultTSQLQuery. Locate doesn't work because I don't know the LastInsertedID. ---------------------------------------------------------------------- panoss · 2014-12-05 10:16 Quote from: kapibara on December 05, 2014, 05:17:03 amA call to Insert puts the query on the position of the new record. The record will be empty and you then assign some values and save the record. If the record is appended, you could call Query.Last after commiting or refreshing the query. Quote from: panoss on December 04, 2014, 07:00:38 pmAfter a new record insert, how can we move the dataset to the new record? Last just move the dataset to the last record. Not to the new inserted. ---------------------------------------------------------------------- exdatis · 2014-12-05 10:29 QuoteIt's SQLite3. I 'm using the defaultTSQLQuery. Locate doesn't work because I don't know the LastInsertedID. See: http://www.sqlite.org/c3ref/last_insert_rowid.html ---------------------------------------------------------------------- panoss · 2014-12-05 10:52 Connection.GetInsertID (before Close,  Open & Refresh of the TSQLQuery) gives the value of the newly inserted iD column! Thanks exdatis!!