ASP obtains the automatic ID of the inserted record.

Source: Internet
Author: User

ASP gets the automatic ID of the newly inserted record. The following lists the two database methods.

ASP + Access2000

1. The property of the ID value field to be obtained must be set to: automatic number (we assume that the field name is recordid)
2. Add record format: Rs. Open table, CN, (note mode)
3. newid = Rs. Fields ("recordid ")
4. newid is the ID value of the newly added record.

ASP/SQL Server 2000

1. The property of the ID value field to be obtained must be set to: automatic number (we assume that the field name is recordid)
2. Add recordCodeMode:

 
CN. Execute "insert into table (field1, field2,...) values (" field1value "," field2value ",...)"

3. Obtain the id value.

 
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 newly added record.
5. Attach three methods to obtain the id value:

/* It is best to use ident_current ('tbname') */insert into table (field1, field2,...) for IDS generated by the last insert operation in a table ,...) values ("field1value", "field2value ",...) select ident_current ('recordid') as newidvalue/* is the most suitable for using the newly inserted Record ID scope_identity () immediately */insert into table (field1, field2 ,...) values ("field1value", "field2value ",...) select scope_identity () as newidvalue/* it is best to use @ identity */insert into table (field1, field2 ,...) values ("field1value", "field2value ",...) select @ identity as newidvalue

The above three methods are successfully tested in the SQL Server Query analyzer. If you want to use the Web code, Please modify it according to the above example.

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.