在.NET程序集添加参数ADODB命令时出错 [英] Error when adding parameters to ADODB command in a .NET assembly

查看:512
本文介绍了在.NET程序集添加参数ADODB命令时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个消耗的是传统的ASP页面中的.NET程序集。我已经创建了一个返回一个ADODB记录的方法。在我的ADODB命令对象,我提供使用以下格式为adCmdStoredProc CommandType属性参数......

 随着ADODBCmd
.ActiveConnection = ADODBConn
。prepared = TRUE
.CommandType = CommandTypeEnum.adCmdStoredProc
.NamedParameters = TRUE
.CommandText = Sql_GetMyBook
.Parameters.Append(.CreateParameter(@书,DataTypeEnum.adChar,ParameterDirectionEnum.adParamInput,50,MyBook))
结束与
 

我得到一个铸件错误...

  

System.Exception的是未处理
  消息= System.InvalidCastException:   无法转换类型的COM对象   系统.__ ComObject类类型   ADODB.InternalParameter。实例   那再present COM组件类型   不能转换到不类型   再present COM组件;然而,他们   只要可以转换为界面   底层COM组件的支持   为的IID的QueryInterface调用   接口

在行:

  .Parameters.Append(.CreateParameter(@书,DataTypeEnum.adChar,ParameterDirectionEnum.adParamInput,50,MyBook))
 

任何想法?

存储过程:

  ALTER PROCEDURE [DBO]。[GetMybook]
     - 添加的参数存储过程在这里
    @book CHAR(50)
如
开始
     -  SET NOCOUNT ON加入到prevent额外的结果集
     - 与SELECT语句的干扰。
    SET NOCOUNT ON;

     - 插入过程语句这里
    SELECT BookTitle,作者,PulishedDate
    从库
    WHERE BookTitle = @书
 

解决方案

是有区别的(意外或没有)在Microsoft ActiveX数据的.CreateParameter方法的返回值的对象库

2.7 - 返回ADODB.InternalParameter(预计由ADODB.Command对象)

2.8 - 返回系统.__ ComObject(该ADODB.Command不能处理或不知道该怎么做)

对于我而言,我不得不改变从2.8我参考2.7库,以创建追加到命令对象参数。

感谢Chris贝伦斯帮我缩小我寻找解决办法。

I have a .NET assembly that is being consumed by a classic ASP page. I've created a method that returns a ADODB recordset. In my ADODB command object I'm supplying parameters using the following format to a adCmdStoredProc CommandType property...

With ADODBCmd 
.ActiveConnection = ADODBConn
.Prepared = True
.CommandType = CommandTypeEnum.adCmdStoredProc
.NamedParameters = True
.CommandText = Sql_GetMyBook   
.Parameters.Append(.CreateParameter("@book", DataTypeEnum.adChar, ParameterDirectionEnum.adParamInput, 50, MyBook))
End With

I get a casting error ...

System.Exception was unhandled
Message=System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'ADODB.InternalParameter'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

at line:

.Parameters.Append(.CreateParameter("@book", DataTypeEnum.adChar, ParameterDirectionEnum.adParamInput, 50, MyBook))

Any ideas?

Stored Proc:

ALTER PROCEDURE [dbo].[GetMybook]
    -- Add the parameters for the stored procedure here
    @book char(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT BookTitle, Author, PulishedDate
    FROM        Library
    WHERE       BookTitle=@book

解决方案

There is a difference (unintended or not) between the return value of the ".CreateParameter" method in Microsoft ActiveX Data objects Library

2.7 - Returns "ADODB.InternalParameter" (which is expected by the ADODB.Command object)

2.8 - Returns "System.__ComObject" (which the ADODB.Command can't handle or doesn't know what to do with)

For my purposes I had to change my reference from 2.8 to 2.7 library in order to append parameters created to the command object.

Thanks to Chris Behrens for helping me narrow down my search for a solution.

这篇关于在.NET程序集添加参数ADODB命令时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆