Microsoft KB Archive/190369

= BUG: RDO LastModified Is Not Consistent After Moving EOF =

Article ID: 190369

Article Last Modified on 11/3/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q190369



SYMPTOMS
When you open an RDO resultset in Visual Basic, if the resultset is positioned at the EOF before issuing an AddNew and Update, the LastModified is the bookmark of the first item in the resultset instead of the newly added item. If the resultset is not positioned at the EOF before the Addnew and Update, the LastModified property correctly points to the newly added record.



RESOLUTION
You can avoid this problem by not positioning the resultset at the EOF before issuing the Addnew and Update methods.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new Visual Basic 6.0 Standard EXE project. From the Project menu, click References. Select Microsoft Remote Data Object 2.0 and click OK.  Add a CommandButton to the default form and paste the following code into the CommandButton Click event.

Note You must modify the connection information to allow you to connect to your database to make sure that you have the appropriate permissions and valid UserID and Password values.

Sample Code
Private Sub Command1_Click

Dim Conn As New rdoConnection Dim CSt As String Dim rs As rdoResultset Dim sSQL As String Dim i As Long

With Conn .CursorDriver = rdUseServer .Connect = "DRIVER={sql server};SERVER=yourserverhere;" & _ "DATABASE=pubs;UID=UserName;PWD=StrongPassword" .EstablishConnection End With sSQL = "SELECT * FROM titles where pub_id = '0877'" Set rs = Conn.OpenResultset(Name:=sSQL, Type:=rdOpenKeyset, _                   LockType:=rdConcurRowVer, Options:=rdExecDirect)

Conn.BeginTrans ' If the resultset was at EOF before the AddNew and Update, ' LastModified will be the bookmark of the first item in       '  the resultset. For instance, the following pubdates will ' be the same. If the resultset is not at EOF, the first ' pubdate will be the date of the newly added row.

rs.MoveLast '<<- These lines cause rs.MoveNext '<<- the problem.

Debug.Print rs.EOF With rs          .AddNew rs("pub_id") = "0877" rs("title_id") = "MC7769" rs("title") = "Test Title" rs("type") = "business" rs("price") = 2.99 rs("advance") = 5000 rs("pubdate") = "01/01/98" .Update

If .Bookmarkable Then .Bookmark = .LastModified 'The following prints the pubdate of the 'first record in the resultset. Debug.Print "Pub date (last modified)= " _ & rs("title_id") Debug.Print "Bookmark = " & .Bookmark 'If you do a MoveLast here, you can get 'to the newly added record. .MoveLast Debug.Print "Pub date (move last) = " _ & rs("title_id") Debug.Print "Bookmark = " & .Bookmark 'The following produces the same as              'the LastModified bookmark. .MoveFirst Debug.Print "Pub date = (move first) " _ & rs("title_id") Debug.Print "Bookmark = " & .Bookmark End If      End With Conn.RollbackTrans

End Sub

 Run this project and click on the CommandButton. You should see that the LastModified property points to the first record in the resultset. If you comment out the lines labeled "These lines cause the problem," then you get the correct value from the LastModified property.

Keywords: kbbug kbpending kbcode KB190369

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.