???? ID: 221931 - ????? ???????: 03 ?????? 2010 - ??????: 2.0

????? DB ??? ???????? ???? ??? ?????? ?? Autonumber ??? ?? ???? ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ?? ??? ??????? ???? ?? ??? ??? Autonumber ????? ??? ??? ActiveX ???? ???????? (ADO) Recordset ????? ??, ?? ????? ?????????? ???????? ??? ??? ??????? ?? ??? Autonumber ????? ?? ??? ???? ??? 0?

?? ???? ????? ???? ?? ?? ADO AddNew() ?? Update() ??????? ??? ?? ???? Access ??????? ??? ???????? ???? ??? ??? ?????? ?? ??? Autonumber ????? ?? ???????? ??? ?? ???? ??? ??????? ???? ?? ??? ???? ????? ?????? ????? ????? (ASP) ?? ???? ????? ??? ????? VBScript ?? ????? ???? ???

???? ???????

????? ??? ????? ?? ?? ???? ???? ?? Adventure ?????? ??????? ?? ?? ???? ??? ??? ODBC ???? ????? ??? (DSN) ??? ????? ???? AdvWorks ????

????? ?? ????? Adovbs.inc, ?? \Program Files\Common Files\System\Ado ??? ??? ????? ????

?? ??? ?????????? ??? ????? ?? ??? ????? ???? ???? ?? ?? ??????? Adventure ?????? ??????? ?????? ?????? ??? ???????? ???? ?? ?? ??? ??????? ?? Autonumber ????? (CustomerID) ?? ??? ????????? ???? ???

????? ?? ??? ???? ?? ??? ??? ????? ???? ???:
  • CursorLocation adUseClient ???? ?????? ??? ????? ?????-???? ????? ???? ?? ?????? ???? ?????
  • Autonumber ????? ?? ???????? ??? ?? ???? ??? ?? ??? ?????????, ???? ?? ??? recordset ?????? ?? requeried Requery ???? ?? ????? ?? ??? ???
  • ????? ???? Requery ???? ?? absolutePosition (????????) ???????? ??? ??? ?? ??????? ?? requeried recordset ?? ???? ??????? ???? ?? ???? ????????????, absolutePosition ?????? Requery ??? ???? ?? ???? ????? ??, ?? ?? ???????? ??? ??? ??????? ???? ?? ??? ???????????? ???? ?? ??? Requery ??? ???? ????
<%@ Language=VBScript %>
<HTML>
<BODY>

<!--#include file=adovbs.inc -->

<% 
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")

objConn.Open "DSN=advworks;"

'Access does not support a cursor engine so a client cursor must be used
objRS.CursorLocation = adUseClient

objRS.Open "SELECT * FROM Customers", objConn, adOpenStatic, adLockOptimistic

     ' when you invoke the method AddNew it adds a new record to the end of           
     ' your current recordset and places your cursor on that record.
     
objRS.AddNew
	objRS("CompanyName") = "Microsoft"
	objRS("ContactFirstName") = "Bob"
	objRS("ContactLastName") = "Smith"
objRS.Update

     ' when you invoke the method Update, it updates the database with the
     ' values of the new record that we just created.  To retrieve the 
     ' value of the Autonumber field we need to update the ADO recordset that
     ' currently have.

     ' When you do a Requery on your recordset, you lose your cursor.  So
     ' we need to store the location before we do the Requery, then reset
     ' it after the Requery.

'before the requery, the Autonumber field shows as 0
Response.Write "<br>ID before Requery = " & objRS("CustomerID")   

bookmark = objRS.absolutePosition  ' First, store the location of you cursor
objRS.Requery                      ' Next, update your recordset with the data from the database

'after the requery, the absolutePosition is the first record of the recordset
Response.Write "<br>ID before setting absolutePosition = " & objRS("CustomerID")

objRS.absolutePosition = bookmark  ' Finally, change your cursor back

'now we have the Autonumber value
Response.Write "<P>Added ID = " & objRS("CustomerID")

objRS.Close
objConn.Close
set objConn = nothing
set objRS = nothing
%>
</BODY>
</HTML>

				

??????

AutoIncrement ????? ?? ADO ?? ????? ???? ?? ???? ??? ???????? ??????? ?? ??? ????? ?????????? ???? ?? Microsoft ???????? ??? ?????:
195910  (http://support.microsoft.com/kb/195910/EN-US/ ) ???????: ADO ?? RDS ??? ????? (AutoIncrement) ?????

???? ???? ???? ??:
  • Microsoft Internet Information Server 3.0
  • Microsoft Internet Information Services 5.0
  • Microsoft Access 2.0 Standard Edition
  • Microsoft Access 97 Standard Edition
??????: 
kbdatabase kbhowto kbinetdev kbmt KB221931 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:221931  (http://support.microsoft.com/kb/221931/en-us/ )