PRB: Chaptered Recordset from Parameterized Query Not SavedID: Q191575
|
If you try to save a hierarchical recordset generated by a parameterized query to a file, the following error appears:
An unknown error has occurred.
Saving a hierarchical recordset generated by a parameterized query is not supported. This behavior is by design.
Const strFileName As String = "C:\Orders.rst"
Private Sub Form_Load()
Dim cnNWindSQL As New ADODB.Connection
Dim rsCustomers As New ADODB.Recordset
Dim rsOrders As ADODB.Recordset
Dim strConn As String
Dim strSQL As String
On Error Resume Next
Kill strFileName
On Error GoTo 0
strConn = "Provider=MSDataShape;" & _
"Data Provider=SQLOLEDB;" & _
"Data Source=scep;" & _
"Initial Catalog=NWindSQL;"
cnNWindSQL.CursorLocation = adUseClient
cnNWindSQL.Open strConn, "sa", ""
If MsgBox("Use parameterized shape?", vbYesNo) = vbYes Then
strSQL = "SHAPE {SELECT * FROM Customers} " & _
"AS Customers APPEND " & _
"({SELECT * FROM Orders WHERE CustomerID = ?} " & _
"AS Orders RELATE CustomerID TO PARAMETER 0) " & _
"AS Orders"
Else
strSQL = "SHAPE {SELECT * FROM Customers} AS Customers " & _
"APPEND ({SELECT * FROM Orders} AS Orders " & _
"RELATE CustomerID TO CustomerID) AS Orders"
End If
With rsCustomers
.Open strSQL, cnNWindSQL, adOpenStatic, _
adLockReadOnly, adCmdText
Set rsOrders = !Orders.Value
If MsgBox("Retrieve all chapters?", vbYesNo) = vbYes Then
While Not .EOF
Debug.Print !CustomerID & " has " _
& rsOrders.RecordCount & " orders."
.MoveNext
Wend
End If
.Save strFileName
.Close
End With
Set rsCustomers = Nothing
cnNWindSQL.Close
Set cnNWindSQL = Nothing
End Sub
An unknown error has occurred.
For additional information about SHAPE command, please see the following article in the Microsoft Knowledge Base:
Q189657 HOWTO: Use the ADO SHAPE Command
http://support.microsoft.com/support/default.asp
Additional query words:
Keywords : kbADO200 kbADO200bug kbprb
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: July 13, 1999