我試圖將表返回到具有50 +列的MS Access,並且行可以從0到5000變化。對於每種情況,可以有多個記錄和車輛類型。SQL Server通過存儲過程將表返回到MS Access
我可以執行存儲過程,它工作正常。我無法將數據返回到MS Access。
存儲的過程代碼:
ALTER PROCEDURE [dbo].[pJDB_Export]
(@dteFrom int,
@dteTo int,
@Veh nvarchar(80))
AS
BEGIN
SET NOCOUNT ON;
DECLARE @stWhere VARCHAR(200)
SELECT DISTINCT [Case]
INTO #tmp
FROM data
WHERE [VEHICLE TYPE] = @Veh
AND (CY BETWEEN @dteFrom AND @dteTo)
SELECT DISTINCT *
FROM dbo.vdata_Export_V3_3_2 v
INNER JOIN #tmp t ON v.[CASE] = t.[CASE]
MS接入代碼:
Function Exec_pJDB_export(sqlConn as string)
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim iFrom, iTo As Integer
Dim stv As String
iFrom = 1999
iTo = 2002
stv = "1 TO 2 TON TRUCKS (COMMERCIAL)"
Set conn = New ADODB.Connection
conn.Open "DSN=Cars"
conn.ConnectionString = sqlConn
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "pJDB_export"
cmd.Parameters.Append cmd.CreateParameter("@dteFrom", adInteger, adParamInput, , iFrom)
cmd.Parameters.Append cmd.CreateParameter("@dteTo", adInteger, adParamInput, , iTo)
cmd.Parameters.Append cmd.CreateParameter("@vehicle", adVarChar, adParamInput, 80, stv)
cmd.Execute
conn.Close
End Function
你有什麼麻煩?代碼是否返回錯誤消息,或者您不確定如何訪問記錄?如果是後者,則需要[ADO記錄集](https://www.w3schools.com/asp/ado_ref_recordset.asp)。 –
沒有任何內容正在返回並且沒有錯誤消息。不知道如何通過ADO訪問記錄 – Draco
檢出ExecuteReader() https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executereader(v=vs.110).aspx – pmbAustin