Error passing parameter to query

  • Thread starter Thread starter octeixeira
  • Start date Start date
O

octeixeira

Guest
Hello to all.

I have the following code:

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim pm As ADODB.Parameter
cn = New ADODB.Connection
rs = New ADODB.Recordset
cmd = New ADODB.Command
pm = New ADODB.Parameter
cn.Open("Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=ORADB)(PORT=1561))" & _
"(CONNECT_DATA=(SERVICE_NAME=PRODL))); uid=APPS;pwd=APPS;")
Dim xl As Microsoft.Office.Interop.Excel.Application
xl = New Microsoft.Office.Interop.Excel.Application
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
wBook = xl.Workbooks.Add

Dim i As Integer = 1

cmd.ActiveConnection = cn
cmd.CommandText = "SELECT i.invoice_date, i.description," _
& " SUM (alb.accounted_cr) - SUM (alb.accounted_dr) remaining_amount" _
& " FROM ap_liability_balance alb, ap_invoices_all i" _
& " WHERE i.vendor_id =19241 AND alb.ORG_ID = 155 and 1=1" _
& " AND trunc(alb.accounting_date) <= :P1 and i.invoice_id = alb.invoice_id" _
& " GROUP BY i.description, i.invoice_date" _
& " HAVING SUM(accounted_cr) <> SUM(accounted_dr)"
pm = cmd.CreateParameter("P1", DataTypeEnum.adDate, ParameterDirectionEnum.adParamInput, 8)
pm.Value = Me.DateTimePicker1.Value.Date
cmd.Parameters.Append(pm)

On the cmd.Parameters.Append(cm) i get the following error: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 components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

I found a few answer by googling but not solved this problem. Can it be that something is wrong before appending the parameter?

Thanks a lot in advance for any kind help.

Octavio

Continue reading...
 
Back
Top