2012-01-31 94 views
0

我有一個訪問2010年,我想在sql 2008服務器上調用sql存儲過程,並將結果返回到記錄集或直接綁定到報表。ms訪問 - 從SQL返回記錄存儲過程

下面的方法返回錯誤「feture在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

您不妨看看http://stackoverflow.com/questions/4184871/adodb-recordset-as-access-report-recordsource – Fionnuala 2012-01-31 21:09:07

回答

0

考慮創建一個視圖以包裹存儲過程(exec usp_whatever)的結果,然後創建鏈接表的新視圖。

此外,您可能可以創建執行存儲過程並直接返回結果的傳遞查詢(exec usp_whatever)。然後將您的報告或表單綁定到查詢。

+0

您不能從存儲過程中選擇*。如果您可以提供有用的傳遞查詢的代碼示例,謝謝。 – Perplexed 2012-01-31 21:56:29

+0

好的,那麼你可以把exec包裝在一個視圖中,或者使用passthrough查詢。 – Beth 2012-01-31 21:58:53

相關問題