Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2004, 06:42 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error trying to call Oracle function in VB.NET

hey all,
here is my question. i created this Oracle function i'd like to call in my VB.NET application, but i get the following error:

 "Specified cast is not valid."

First, here is the code for creating the Oracle function:

CREATE FUNCTION "ORDERITEMS" (ShippableItemID NUMBER) RETURN NUMBER is
inventory_count NUMBER;
enrollment_count NUMBER;

BEGIN
SELECT InventoryCount INTO inventory_count
FROM SHIPPABLEITEM
WHERE SHIPPABLEITEMID = ShippableItemID
AND Rownum = 1;

SELECT DISTINCT COUNT (COURSERECORD.StudentID) INTO enrollment_count
FROM COURSEINSTANCEMATERIALS, COURSERECORD
WHERE COURSEINSTANCEMATERIALS.ShippableItemID = ShippableItemID
AND COURSERECORD.CourseInstanceID = COURSEINSTANCEMATERIALS.CourseInstanceID;

IF (inventory_count < 0.5*enrollment_count) THEN
    RETURN 1;
ELSE
    RETURN 0;
END IF;
END;

I tested it in SQL *Plus and it worked fine. Now then, here is the part of my VB.NET code performing the call to the above function:

 DBCommand = New ADODB.Command
 DBRecords = New ADODB.Recordset
 DBCommand.ActiveConnection = DBLink

 Dim InputParameter As New ADODB.Parameter
 Dim ReturnValue As New ADODB.Parameter

 ItemIDValue = DBRecords.Fields(0).Value

 DBCommand.CommandText = "OrderItems"
 DBCommand.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc

 InputParameter.Name = "ShippableItemID"
 InputParameter.Direction = ADODB.ParameterDirectionEnum.adParamInput
 InputParameter.Type = ADODB.DataTypeEnum.adInteger
 InputParameter.Value = ItemIDValue

 ReturnValue.Name = "myReturnValue"
 ReturnValue.Direction = ADODB.ParameterDirectionEnum.adParamReturnValue
 ReturnValue.Type = ADODB.DataTypeEnum.adInteger

 'Add parameters to ADODB command.
 DBCommand.Parameters.Append(InputParameter) --> ERROR ON THIS LINE
 DBCommand.Parameters.Append(ReturnValue)

 Try
    'Executes the command.
    DBFunctionResult = DBCommand.Execute()
 Catch ex As Exception
    MsgBox("Failed to call Oracle function ORDERITEMS.")
 End Try

 If Not DBFunctionResult.EOF Then
    Do Until DBFunctionResult.EOF
       ReturnFlag = DBFunctionResult.Fields(0).Value
       MsgBox("Function return value: " & ReturnFlag)
    Loop
 End If

I get the error in the line marked (DBCommand.Parameters.Append(InputParameter)). I tried setting the type of parameter InputParameter as adNumeric, but got the same error. Any ideas?

Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to call asp.et and vb.net function using javas dilipv General .NET 3 March 27th, 2008 02:44 PM
call oracle function using oracle link server vl SQL Server 2000 1 July 12th, 2007 08:19 AM
Calling Oracle function from Vb.net class monuindia2002 ADO.NET 1 August 4th, 2006 05:00 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Call a function from Oracle in C# Rabab C# 1 February 16th, 2004 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.