我有一个访问权限2010,我想在sql 2008服务器上调用sql存储过程并将结果返回到记录集或直接绑定到报表。
下面的方法会返回错误“ADP中不可用的错误”或类似内容 - 它适用于表单但不适用于报表。
我该怎么做?
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim cm As New ADODB.Command
'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection
With cn
.Provider = "Microsoft.Access.OLEDB.10.0"
.Properties("Data Provider").Value = "SQLOLEDB"
.Properties("Data Source").Value = "dsidsw923"
.Properties("Integrated Security").Value = "SSPI"
.Properties("Initial Catalog").Value = "Promotions_Dev_DSI"
.Open
End With
'Create an instance of the ADO Recordset class, and
'set its properties
Set rs = New ADODB.Recordset
With cm
.ActiveConnection = cn
.CommandText = "spCheckProdWkConsist"
.CommandType = adCmdStoredProc
Set rs = .Execute()
End With
'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Set cm = Nothing
答案 0 :(得分:0)
考虑创建一个视图来包装存储过程的结果(exec usp_whatever
),然后创建一个链接表到新视图。
此外,您可以创建执行存储过程的直通查询(exec usp_whatever
)并直接返回结果。然后将报表或表单绑定到查询。