This article mainly introduces the method for ASP to obtain the ID value of new records. It also introduces the methods for obtaining the two databases of ASP+Access2000 and ASP+SQL Server 2000. Friends in need can refer to the following
ASP+Access2000
1. The ID value field attribute to be obtained must be set to: automatic number (we assume the field name is recordID)
2. Add record format: Rs.Open table,Cn,1,3
Note that the modes are: 1,3
3.newID = rs.Fields("recordID")
4.newID is the ID value of the record just added
ASP+SQL Server 2000
1. The ID value field attribute to be obtained must be set to: automatic number (we assume the field name is recordID)
2. Add record code mode:
Copy the code code as follows:
Cn.Execute"INSERT INTO table(field1,field2,...) VALUES("field1Value","field2Value",...)"
3. Get the ID value
Copy the code code as follows:
Set Rss = Cn.Execute("SELECT SCOPE_IDENTITY() as newIDValue FROM table")
'Rs.Open sqlStr,Cn,3,1
newID = Rss("newIDValue")
4.newID is the ID value of the record just added
5. Attached are three ways to obtain the ID value:
Copy the code code as follows:
/* For those who want to get the ID generated by the last insert operation in a table, it is best to use IDENT_CURRENT('TBName')*/
INSERT INTO table(field1,field2,...) VALUES("field1Value","field2Value",...) SELECT IDENT_CURRENT('recordID') as newIDValue
/*It is most appropriate to use SCOPE_IDENTITY() for the new record ID just inserted for immediate use*/
INSERT INTO table(field1,field2,...) VALUES("field1Value","field2Value",...) SELECT SCOPE_IDENTITY() as newIDValue
/*If you want to get the last self-increasing ID in a series of operations, it is best to use @@IDENTITY*/
INSERT INTO table(field1,field2,...) VALUES("field1Value","field2Value",...) SELECT @@IDENTITY as newIDValu