加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在.NET程序集中向ADODB命令添加参数时出错

发布时间:2020-12-16 09:21:37 所属栏目:asp.Net 来源:网络整理
导读:我有一个由传统ASP页面使用的.NET程序集.我创建了一个返回ADODB记录集的方法.在我的ADODB命令对象中,我使用以下格式向adCmdStoredProc CommandType属性提供参数… With ADODBCmd .ActiveConnection = ADODBConn.Prepared = True.CommandType = CommandTypeEn
我有一个由传统ASP页面使用的.NET程序集.我创建了一个返回ADODB记录集的方法.在我的ADODB命令对象中,我使用以下格式向adCmdStoredProc CommandType属性提供参数…

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

我得到一个投射错误……

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.

在线:

.Parameters.Append(.CreateParameter("@book",MyBook))

有任何想法吗?

存储过程:

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

解决方法

Microsoft ActiveX数据对象库中“.CreateParameter”方法的返回值之间存在差异(无意或无意)

2.7 – 返回“ADODB.InternalParameter”(ADODB.Command对象需要)

2.8 – 返回“System .__ ComObject”(ADODB.Command无法处理或不知道如何处理)

出于我的目的,我不得不将我的引用从2.8更改为2.7库,以便将创建的参数附加到命令对象.

感谢Chris Behrens帮助我缩小搜索范围.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读