ASP get new Record ID value method _ Application Tips

Source: Internet
Author: User

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:

Copy Code code as follows:
Cn.execute INSERT into table (Field1,field2,...) VALUES ("Field1value", "Field2value",...) "

3. Get ID Value
Copy 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 for the ID value of the record you just added
5. Attach three ways to obtain the ID value:
Copy Code code 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.