gpt4 book ai didi

sql-server-2008 - 如何从 MS Access VBA 中调用 SQL Server 存储过程

转载 作者:行者123 更新时间:2023-12-04 18:12:06 25 4
gpt4 key购买 nike

我有一个带有参数但不返回任何内容的存储过程。如何从 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

最佳答案

这是一个可能会有所帮助的大纲。稍后我可能会回来提供更多详细信息。它并不特定于您的情况,但它可能会让您继续前进:)

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

关于sql-server-2008 - 如何从 MS Access VBA 中调用 SQL Server 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12404805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com