MartinSmithhh
Programmer
I came across some pretty useful sample code to insert a new record and retrieve the identity but I am not sure how it works!
I would be grateful if anyone has any info and or links which explain this further.
specifically
1. what is the significance of the '0' in RS(0)?
2. Is this more efficient than 2 separate queries?
3. Can this technique be used for anything else apart from retrieving identities?
Thanks,
Martin
Code:
Dim new_identity
'Doing an insert
Query = "INSERT INTO ComDirMOTD " & _
"(title, sender_text, message_body, Hyperlink, body_backcol, " & _
"ConfirmationValue, StartDate, EndDate, login_of_requestor) " & _
"VALUES ('" & MessageTitle & "','" & SenderName & "','" & MessageBody & "','" & Hyperlink & "','" & BodyColor & "','" & MOTDConfirm & "','" & StartDate & "','" & EndDate & "','" & LogInOfRequestor & "')"
Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
Set RS = Conn.Execute(Query & ";" & "select @@identity").NextRecordset
'Retrieve the motd_id for the newly inserted record
new_identity = RS(0)
Set RS = Nothing
I would be grateful if anyone has any info and or links which explain this further.
specifically
1. what is the significance of the '0' in RS(0)?
2. Is this more efficient than 2 separate queries?
3. Can this technique be used for anything else apart from retrieving identities?
Thanks,
Martin