This article mainly introduces the method of obtaining new record ID value by ASP, introduces the method of obtaining asp+access2000 and asp+sql Server 20,002 kinds of database, and the friends who need it can refer to
asp+access2000
1. The ID Value field property to get must be set to: AutoNumber (we assume the field name is RecordID)
2. Add record format: Rs.Open table,cn,1,3
Note Mode is: 1,3
3.newID = Rs. Fields ("RecordID")
4.newID for the ID value of the record you just added
Asp+sql Server 2000
1. The ID Value field property to get must be set to: AutoNumber (we assume the field name is RecordID)
2. Add record code mode:
The code is as follows:
Cn.execute INSERT into table (Field1,field2,...) VALUES ("Field1value", "Field2value",...) "
3. Get ID Value
The code is as follows:
Set Rss = Cn.execute ("Select Scope_identity () as newidvalue from table")
' Rs.Open sqlstr,cn,3,1
NewID = Rss ("Newidvalue")
4.newID for the ID value of the record you just added
5. Attach three ways to obtain the ID value:
The code is as follows:
/* The best use of ident_current (' Tbname ') for the ID to be generated by the last insert in a table.
INSERT into table (Field1,field2,...) VALUES ("Field1value", "Field2value",...) SELECT ident_current (' RecordID ') as Newidvalue
/* The scope_identity () is the most appropriate for the new record ID just inserted in the immediate use.
INSERT into table (Field1,field2,...) VALUES ("Field1value", "Field2value",...) SELECT scope_identity () as Newidvalue
/* It is best to use the @ @IDENTITY/* For the last ID that you want to get from a series of operations
INSERT into table (Field1,field2,...) VALUES ("Field1value", "Field2value",...) SELECT @ @IDENTITY as Newidvalu