Getting key field value after insert 
Author Message
 Getting key field value after insert

I have a table that has only one unique key field that increases
automatically when a new record is added.
In order to get a hold of this value after inserting a record I use:

sSql.Format("SELECT * from UTBMOTT WHERE sPersnr = '%s' ORDER BY lMottagare
DESC", m_szPersnr);

rs->Open(CRecordset::dynaset, sSql))
......
rs->AddNew();
rs->>Update();
rs->MoveLast();

and after this I can retrieve the key field value.

When I open the recordset I don't really want it to contain any records.

Is there a way to open the recordset without any records in it and still be
able to use it to retieve the key feild value ? Or is there an easier way to
get a hold of the key field value ?

Thanks in advance,
Pernilla



Sun, 08 Dec 2002 03:00:00 GMT
 Getting key field value after insert

Hi,
   Yes!
   Try sSql.Format("SELECT * from UTBMOTT WHERE 1=0 and sPersnr = '%s'
ORDER BY lMottagare
DESC", m_szPersnr);


Sun, 08 Dec 2002 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. Getting the next available key value for a table and insert a new record

2. Getting primary key value after insert

3. Getting the next available key value for a table and insert a new record

4. Getting (Key Field) Value

5. Getting the value of an autoincrement or identity field during an sql insert

6. Getting back an identity field value after an insert SQL statement

7. Getting an autonumber field value after inserting with ADO

8. Getting the value of an autoincrement or identity field during an sql insert

9. Attempt to insert duplicate identity values in table (has identity and key fields)

10. Returning key field value from an ADO.Command Insert statement

11. Trigger on Insert / Getting Newly Inserted Primary Key

12. inserting a field value into another field automatically


 
Powered by phpBB® Forum Software