Hi guys wondering if someone can help me with doing a retrieval of the new inserted data.
I have tried several versions found on the net but they always error does anyone have a working example of one that they could provide or a way of actuallly managing it as I am struggling with it.
I have managed to get it working
strCon.Execute("INSERT INTO Ticket(Raised_By_ID, Raised_By) VALUES(" & session("ncruserid") & ", '"& session("ncrname") &"');") ' Execute the insert command
Set rsNewID = strCon.Execute("SELECT @@IDENTITY")
intNewID = rsNewID(0) ' Store the value of the new identity in variable intNewID
rsNewID.Close
Set rsNewID = Nothing
strCon.Close
that should work except that it will return the last inserted id from any table not just the one you were working with (if you have stored procedures or tiggers that will affect it) if you need something to be a little more solid let me know there are a couple other methods provied you are using ms sql
i have used something other than the methods listed above to do this with access, they are frowned upon but work nicely if you would like to try it....
no, it uses a record set to do the adding which is why it is frowned upon...
Code:
<%
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("_database/complaints.mdb")
dim rsAddNewUser
dim strSQl
Set rsAddNewUser = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM users"
'Query the database
rsAddNewUser.Open strSQL, strCon, 3, 2
'Add a new record to the recordset
rsAddNewUser.AddNew
rsAddNewUser("first_name") = request.Form("first_name")
rsAddNewUser("last_name") = request.Form("last_name")
rsAddNewUser("user_name") = request.Form("user_name")
rsAddNewUser.Update
dim identvar
identvar = rsAddNewUser("identity")
'do action with identity here
'Reset Sever Objects
rsAddNewUser.close
set rsAddNewUser = nothing
%>
that should get you started...i have not found a way to port this over to.net, but that doesn't matter when i use .net i use ms sql...