PRB: ADO Does Not Return Records After an UpdateID: Q197528
|
When issuing an Update, Insert, or Delete statement followed by a Select statement from an ADO client application, referencing the ADO recordset object would generate the following error:
Run-time error '3265':
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.
The execution of the update statement against SQL Server returns a message with the number of records affected by the Update, Insert, or Delete statement (pcRowsAffected.) This number of records message will be cached in the TDS stream. When the calling application checks for results, the actual recordset will be waiting on the pipe after the records affected message.
There are two possible workarounds to the this behavior:
This behavior is by design.
Option Explicit
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rst As ADODB.Recordset
Dim Str As String
With cn
.Provider = "SQLOLEDB"
.Open "Data Source=Test;User ID=sa;Password=;"
.DefaultDatabase = "Pubs"
End With
' Un-comment the following line to demonstrate Workaround 1
' cn.Execute "SET NOCOUNT ON "
' Passing an Insert statement followed by a Select statement
' as the source of the recordset
Str = "Insert into Jobs (job_desc, min_lvl, max_lvl) Values " _
& "('Support Professional', 25, 75) " _
& " Select * from Jobs"
rs.CursorLocation = adUseClient
rs.Open Str, cn, adOpenStatic, adLockOptimistic, adCmdText
' Un-comment the following two lines to demonstrate Workaround 2
' Set rst = rs.NextRecordset
' MsgBox rst(1)
' For workaround 2, please comment the following line
MsgBox rs(1)
MsgBox "Done..."
cn.Close
End Sub
For additional information about SET NOCOUNT option, please refer to the Transact SQL Help and search for SET NOCOUNT.
Additional query words: kbdse
Keywords : kbADO kbDatabase kbMDAC kbOLEDB kbSQLServ
Version : WINDOWS:2.0,2.01
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 2, 1999