Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27417

VS 2010 Receiving error while passing parameter to query

$
0
0
Hello to all.

I have the following code:

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 already tried using
Code:

@P1
and
Code:

?
instead of
Code:

:P1
but the error persists.

I found a few answers 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

Viewing all articles
Browse latest Browse all 27417

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>