ASP to obtain new record ID value method

Source: Internet
Author: User

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

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.