Solved

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

Posted on 2011-09-08
6
1,295 Views
Last Modified: 2012-06-22
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

0
Comment
Question by:ict-torquilclark
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:thewild
ID: 36501391
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

0
 
LVL 1

Author Comment

by:ict-torquilclark
ID: 36501420
I have tried that but visual studio just puts them back in.
0
 
LVL 4

Expert Comment

by:thewild
ID: 36501442
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:ict-torquilclark
ID: 36503188
nope that daoes work either :(
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36506255
You may have been asked many times before but do you HAVE to use ADODB in VB.NET?
0
 
LVL 4

Accepted Solution

by:
thewild earned 500 total points
ID: 36508393
There might be a problem with the ADO library you are referencing.
Wich version number is it ?
Can you try with another one (lower or higher version number) ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to know if my Checkbox is True in VB6.0? 9 40
vb.net - How to check if current user is an administrator? 6 34
Advice in Xamarin 21 56
Help with LINQ and XML 10 27
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now