用于运行 SQL Server 过程的 ADODB 连接

发布于 2024-08-22 05:20:52 字数 1541 浏览 7 评论 0原文

我目前正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘然心甜 2024-08-29 05:20:52

您在哪里设置存储过程的名称?
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 call Parameters.Append

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文