Hi,
Sorry if this has been asked before, but I can't work it out:
I'm doing an insert into an access table, which has an autonumber id. after the insert, I wantto retrieve the ID which was allocated so that I can query back the new record.
I'm trying to do it like this (only one person will be updating so its ok to go for max(id)):
But it seems to be picking up the max(id)before the record that was just inserted. Am I missing something?
thanks,
tamsin [sig][/sig]
Sorry if this has been asked before, but I can't work it out:
I'm doing an insert into an access table, which has an autonumber id. after the insert, I wantto retrieve the ID which was allocated so that I can query back the new record.
I'm trying to do it like this (only one person will be updating so its ok to go for max(id)):
Code:
sQry = "insert into staff ...";
var upd = Server.CreateObject('ADODB.Command');
upd.ActiveConnection = "dsn=DB_Generic";
upd.CommandText = sQry;
upd.Execute();
var rstnewID = Server.CreateObject("ADODB.Recordset");
rstnewID.ActiveConnection = "dsn=DB_Generic";
rstnewID.Source = "SELECT max(staffid) FROM staff";
rstnewID.Open();
var newID = rstnewID.Fields.Item(0).Value;
But it seems to be picking up the max(id)before the record that was just inserted. Am I missing something?
thanks,
tamsin [sig][/sig]