存储过程vba中的参数

时间:2013-12-05 10:32:21

标签: vba stored-procedures parameters

我的代码存在一些问题:

Dim title, datee As String
Dim ConnectionString As String
Dim sPassword As String
Dim sUser As String
Dim sDatabase As String
Dim sServer As String
Dim req As String
Dim Cmd1  As New ADODB.Command
Dim AConn As New ADODB.Connection
Dim Rst As ADODB.Recordset
Dim dateee As Date
dateee = "2013-10-10"
Dim prm As ADODB.Parameter

title = Cells(1, 6).Value
datee = Cells(2, 4).Value
Range("A6:Z65500").ClearContents

title = Left(title, Len(title) - 10) + datee
Cells(1, 6).Value = title
sServer = Worksheets("BaseDeDonnees").Cells(3, 3)
sDatabase = Worksheets("BaseDeDonnees").Cells(4, 3)
sUser = Worksheets("BaseDeDonnees").Cells(5, 3)
sPassword = Worksheets("BaseDeDonnees").Cells(6, 3)

AConn.ConnectionString = "UID=" & sUser & ";PWD=" & sPassword & ";" & "DRIVER={SQL Server};Server=" & sServer & ";Database=" & sDatabase & ";"
AConn.Open

Cmd1.ActiveConnection = AConn
Cmd1.CommandText = "test"
Cmd1.CommandType = adCmdStoredProc

Set prm = Cmd1.CreateParameter("@dateMax", adDBTimeStamp, adParamInput)
Cmd1.Parameters.Append prm
Cmd1.Parameters("@dateMax").Value = dateee

Set prm = Cmd1.CreateParameter("@usrID", adInteger, adParamInput)
Cmd1.Parameters.Append prm
Cmd1.Parameters("@usrID").Value = 100768

Cmd1.Execute
AConn.Close

我有一条错误消息:过程或函数'test'需要参数'@usrID',这是未提供的。我真的不知道为什么我有这个错误,@ usrID,定义了... 你能帮助我吗 ?谢谢:))

2 个答案:

答案 0 :(得分:0)

我传递给存储过程的任何参数(至少对于SQL Server),我已经传入,因为我已经创建了参数。所以在你的情况下我会按如下方式这样做:

Set prm = Cmd1.CreateParameter("@usrID", adInteger, adParamInput, 4, 100768)
Cmd1.Parameters.Append prm

或者如果你像我一样懒惰:

Cmd1.Parameters.Append Cmd1.CreateParameter("@usrID", adInteger, adParamInput, 4, 100768)

注意,倒数第二个参数是输入的大小(以字节为单位)或字符串(varchars)长度,最后一个参数是传递的值。

更多信息: http://msdn.microsoft.com/en-us/library/windows/desktop/ms677209%28v=vs.85%29.aspx

答案 1 :(得分:0)

您需要添加:

$ awk '{a[$1]=$2} sub(/;/,""){print a["HOST"], a["PORT"], a["DATABASE"], $2}' file
dev@opulex.com 1066 ORACLE_1 DEPT.*
dev@opulex.com 1066 ORACLE_1 EMP.*
dev@opulex.com 1066 ORACLE_2 JOB.*
dev@opulex.com 1066 ORACLE_2 SALARY.*
orl@opulex.com 89 MYSQL_1 PURCHASE.*
orl@opulex.com 89 MYSQL_2 PRICE.*
orl@opulex.com 89 MYSQL_2 PRODUCT.*

在分配参数之前,否则它们实际上是按位置传递的。