'------ Powered by YESOUL SOFT without fast white guest original, exchange QQ: 115269, please keep this information, work unit: kiss my entertainment expert
http://www.772.cn ----------- '
This article will introduce the key to explain how to update or add a record in MS SQL Server to get the value of its identity column, this value is the automatic number we are well known.
ID value, ok, gossip, don't write, I don't have much to write, I only write key, I believe you will understand, huh, huh. The following also included the method acquired in Access, although in Access
Although there are many articles on the article in the automatic number, it is a summary of this.
Set testrs = server.createObject ("AdoDb.Recordset") 'Creating objects to test
TestRs.open "[TestTable]", conn, 1, 2 'assumes that CONN has been created, and the database has been connected
Testrs.Addnew
TestRS ("colname1") = "colname1"
TestRS ("colname2") = "colname2"
......
TestRS ("colnamen" = "colnamen"
TestRs.Update 'calls the UPDATE method to immediately write data in the memory into the database, the following sentence is key
Testrs.movelast 'will record the last one
ID = TestRS ("ID") 'This can immediately get the automatic number of this new record just now.
Finally don't forget to close the object
Testrs.close: set testrs = Nothing
Oh, I have been tested in Windows 2000 Server SP4 MS SQL Server ASP / VB / DELPHI, all are feasible. Because this article is for some basic people reading, the above code is not directly running. If you have questions about the code on the above, please contact me QQ: 115269, or go to my website to entertain: http: //www.772.cn/
the following
Reposted how to get the ID value of the automatic number after inserting the record in the Access database
First of all, you must ensure that the Bookmark property is supported by the record set, such as 1,3
After inserting a record with an automatic number field, get the Bookmark property value of the record
Temp = rs.bookmark
then
rs.bookmark = TEMP
Try! !
Response.write
RS ("ID").
By the way, what is the property of Bookmark, because now there is a bit ambiguous on the Internet :)
Returns the bookmark that is the current record in the Recordset object (we can return to his automatic number after Access to add a new record), or set the current record of the Recordset object to be identified by the effective bookmark.
Setting and return value
Set or return a variant-type expression that calculates a valid bookmark.
Description
Use the Bookmark property to save the current recorded position and return to the record at any time. Bookmarks can only be used in Recordset objects that support bookmark functions.
When you open the Recordset object, each record has a unique bookmark. To save the current recorded bookmark, assign the value of the Bookmark property to a variable. When moving to other records, return to the record quickly, set the BookMark property of the Recordset object to the value of the variable.
The user may not be able to view the value of the bookmark, and it is also not possible to compare the bookmark (pointing to the two bookmarks of the same record).
If you use a Clone method to create a copy of the Recordset, the original and replicated RecordSet object bookmark property settings are the same and can be replaced. However, the bookmarks of different RecordSet objects cannot be replaced, even if these bookmarks are created by the same data source or command.
The Bookmark property is always valid when the remote data service is used on the client (Ador) Recordset object.