如何调用SQL服务器的MS Access VBA内存储过程从(How to call SQL Ser

2019-09-22 09:38发布

我有一个存储过程,采用参数,但不返回任何东西。 我该如何把它从MS Access中?

编辑 - 随着Remou的帮助下,我找到了工作:

Set cnn = New adodb.Connection
cnn.ConnectionString = 
   "driver=SQL Server;server=SERVER\SERVER;database=a_db;Trusted_Connection=Yes"

cnn.Open cnn.ConnectionString

Set cmd = New adodb.Command
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "stprMoveDataSet"

Set param = cmd.CreateParameter
                ("DataSetID", adInteger, adParamInput, 6, stDataSet)
cmd.Parameters.Append param
Set param = cmd.CreateParameter
                ("Destination", adChar, adParamInput, 2, stDestination)
cmd.Parameters.Append param

rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open cmd

Answer 1:

下面是一个大纲,可以帮助。 我或许能够找回更多的细节稍后。 它不是具体到你的情况,但它可能让你去:)

Public dbconn As ADODb.Connection
Dim cmd As New ADODb.command
Dim rs As New ADODb.Recordset
Dim param As New ADODb.Parameter

Set dbconn = New ADODb.Connection
dbconn.ConnectionString = GetServerCon

dbconn.Open dbconn.ConnectionString

Set cmd = New ADODb.command
cmd.ActiveConnection = dbconn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "insert_user"

Set param = cmd.CreateParameter(_
   "username", adVarChar, adParamInput, 50, Environ("UserDomain") & "dddddddd\" _
   & Environ("Username"))
cmd.Parameters.Append param

rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open cmd


文章来源: How to call SQL Server Stored Procedure from within MS Access VBA