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.