Avatar of ict-torquilclark
ict-torquilclark

asked on 

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 compo

I am using ADODB to run a sql strored procedure in VB.Net.

when my code gets to the line

cmd.Parameters.Append(cmd.CreateParameter("CampaignName", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50, "Annuities"))

I get the error in the title.

Can anybody suggest wy?
sqlstr = "SELECT * FROM WebEnquiries WHERE WebEnquiryID = '" & WebEnquiryID & "'"
        rs.Open(sqlstr, sqlCnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

        If rs.RecordCount = 0 Then
            rs.Close()
            Exit Function
        End If


        Dim cmd As New ADODB.Command
        Dim cnn As New ADODB.Connection

        cnn.ConnectionString = sqlDialler
        cnn.Open()

        cmd.ActiveConnection = cnn
        cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
        cmd.CommandText = "InsertCampaignRecord"

        cmd.Parameters.Append(cmd.CreateParameter("CampaignName", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50, "Annuities"))
        cmd.Parameters.Append(cmd.CreateParameter("Tel1", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 20, rs.Fields("daytime_telephone").Value))

Open in new window

Visual Basic.NETVisual Basic Classic

Avatar of undefined
Last Comment
thewild
Avatar of thewild
thewild
Flag of Belgium image

I believe the parenthesis are confusing Access.
Could you try :
cmd.Parameters.Append cmd.CreateParameter("CampaignName", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50, "Annuities")

Open in new window

Avatar of ict-torquilclark
ict-torquilclark

ASKER

I have tried that but visual studio just puts them back in.
Avatar of thewild
thewild
Flag of Belgium image

Really ? That's weird.
Maybe you should "call" the method then ?

Call cmd.Parameters.Append(cmd.CreateParameter("CampaignName", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50, "Annuities"))

Open in new window

Avatar of ict-torquilclark

ASKER

nope that daoes work either :(
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

You may have been asked many times before but do you HAVE to use ADODB in VB.NET?
ASKER CERTIFIED SOLUTION
Avatar of thewild
thewild
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo