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,276 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

16 Experts available now in Live!

Get 1:1 Help Now