用于运行 SQL Server 过程的 ADODB 连接
我目前正在尝试在 VB6 中运行某个过程(sql 2005),传递一些参数:
Dim conn As Connection
Set conn = New Connection
conn.Open "Provider=whateverprovider;Data Source=whateversource;Database=whateverdatabase;User Id=whateverID;Password=whatever"
Dim CMD As ADODB.Command
Dim rs As ADODB.Recordset
Set CMD = New ADODB.Command
Set CMD.ActiveConnection = conn
CMD.CommandType = adCmdStoredProc
CMD.Parameters.Append CMD.CreateParameter("@EmpresaCNPJ", adVarChar, adParamInput, 14, "64687015000152")
CMD.Parameters.Append CMD.CreateParameter("@EntradaSaida", adChar, adParamInput, 1, "S")
CMD.Parameters.Append CMD.CreateParameter("@Participante", adVarChar, adParamInput, 60, "0000000020")
CMD.Parameters.Append CMD.CreateParameter("@nroNotaFiscal", adInteger, adParamInput)
CMD.Parameters("@nroNotaFiscal").Value = 2289
CMD.Parameters.Append CMD.CreateParameter("@serieNotaFiscal", adSmallInt, adParamInput)
CMD.Parameters("@serieNotaFiscal").Value = 1
Set rs = CMD.Execute
在最后一行中,我收到以下错误消息:
替代文本 http://dl.dropbox.com/u/3045472/ERRO.png
英文内容如下: “语法错误或访问冲突”
这条消息非常通用,我不知道问题出在哪里。
我做错了什么?
以下是过程中 sql 代码的参数接收部分:
@EmpresaCNPJ varchar(14),
@EntradaSaida char(1)=null,
@Participante varchar(60)=null,
@nroNotaFiscal int=null,
@serieNotaFiscal smallint=null,
@EtapaInicial tinyint=null,
@LineComplement varchar(255)=null
我被告知并非每个参数都应该传递,并且它应该只使用五个(七个中的)。
I'm currently trying to run a certain procedure (sql 2005) in VB6, passing some parameters:
Dim conn As Connection
Set conn = New Connection
conn.Open "Provider=whateverprovider;Data Source=whateversource;Database=whateverdatabase;User Id=whateverID;Password=whatever"
Dim CMD As ADODB.Command
Dim rs As ADODB.Recordset
Set CMD = New ADODB.Command
Set CMD.ActiveConnection = conn
CMD.CommandType = adCmdStoredProc
CMD.Parameters.Append CMD.CreateParameter("@EmpresaCNPJ", adVarChar, adParamInput, 14, "64687015000152")
CMD.Parameters.Append CMD.CreateParameter("@EntradaSaida", adChar, adParamInput, 1, "S")
CMD.Parameters.Append CMD.CreateParameter("@Participante", adVarChar, adParamInput, 60, "0000000020")
CMD.Parameters.Append CMD.CreateParameter("@nroNotaFiscal", adInteger, adParamInput)
CMD.Parameters("@nroNotaFiscal").Value = 2289
CMD.Parameters.Append CMD.CreateParameter("@serieNotaFiscal", adSmallInt, adParamInput)
CMD.Parameters("@serieNotaFiscal").Value = 1
Set rs = CMD.Execute
In the last line i get the following error message:
alt text http://dl.dropbox.com/u/3045472/ERRO.png
Which in English it reads:
"syntax error or access violation"
This message is REALLY generic, and I don't have a clue about where could the problem be.
What did i do wrong ?
Here is the parameter receiving part of the sql code in the procedure:
@EmpresaCNPJ varchar(14),
@EntradaSaida char(1)=null,
@Participante varchar(60)=null,
@nroNotaFiscal int=null,
@serieNotaFiscal smallint=null,
@EtapaInicial tinyint=null,
@LineComplement varchar(255)=null
I was told that not every parameter should be passed, and that it should work with just five (out of seven).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里设置存储过程的名称?
cmd.CommandName = ....
编辑:在开始调用
Parameters.Append
之前,将CommandName
设置为存储过程的名称Where are you setting the name of the stored procedure?
cmd.CommandName = ....
EDIT: Set the
CommandName
to the name of the stored procedure, before you begin to callParameters.Append