Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 13th, 2004, 05:42 PM
Registered User
 
Join Date: Jan 2004
Location: , , .
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.

Closed Thread


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05:03 AM
Call a function from Oracle in C# Rabab C# 1 February 16th, 2004 09:18 AM



All times are GMT -4. The time now is 08:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.