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

标签 .net asp-classic assemblies adodb consumption

我有一个由经典 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", DataTypeEnum.adChar, ParameterDirectionEnum.adParamInput, 50, 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 帮助我缩小了解决方案的搜索范围。

关于.net - 向 .NET 程序集中的 ADODB 命令添加参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4818552/

相关文章:

c++ - 如何访问 native IDataObject

c# - 选择设计模式的建议

c# - 我可以在我拥有的_every_ 项目的同一目录中禁用 obj 的生成吗?

xml - 将 XML 发布到经典 asp 页面并检索页面上的发布数据

javascript - 在 JavaScript 中通过 innerHTML 从列表中删除项目

c# - 我可以使用 RandomNumberGenerator.GetInt32() 方法生成密码安全的随机字符串吗?

xml - 经典 ASP .loadXML(XMLstring) 读出空白?

.net - 您是否对您的产品使用的所有程序集进行强命名?

c# - 如何从程序集中只公开一个特定的类?

webforms - ASP.NET 4.5 应用程序预热导致确定加载的程序集时出错