old ADO in VB.NET

K

Kovan A.

I am having a small problem using old ADO in VB.NET (i am maintaing old code
so i cant change it back to ADO.NET)
i am trying to create ADODB.Parameters and then pass them to ADODB.Command
and it seems to fail every time
I have referenced the adodb.dll in PIA to use the old ado., and i am using
ado 2.7

Parameters is an array of ADODB.Parameter
any help would be appreciated it

Kovan,

here is the code (keep in mind my stored procedure parameters match the
parameters in param()


Dim cmd As New ADODB.Command

cmd.CommandText = strSPName

cmd.CommandType = CommandTypeEnum.adCmdStoredProc

cmd.ActiveConnection = adoConn

'if we were given a parameters collection, append them to the command

If Not Parameters Is Nothing AndAlso Parameters.Length > 0 Then

Dim param As ADODB.Parameter

For Each param In Parameters

cmd.Parameters.Append(param) 'ERROR HAPPENS HERE (InvalidCastException)

Next

End If

cmd.Execute(, , ADODB.ExecuteOptionEnum.adExecuteNoRecords)

rs = Nothing
 
C

Cor

Hi Kovan,

This did work for me.
Dim par(0) As ADODB.Parameter
par(0) = New ADODB.Parameter
par(0) = cmd.CreateParameter("b", ADODB.DataTypeEnum.adChar, _
ADODB.ParameterDirectionEnum.adParamInput, 1, "B")
For Each param As ADODB.Parameter In par
cmd.Parameters.Append(param)
Next
I hope this helps?
Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top