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,343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

737 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