Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 30th, 2004, 02:51 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call a function from Oracle in C#

Hello
I need the code that can be used to call a function with both input and output parameters ,through C# code ....
note that this function is in Oracle db....and it's a function not a procedure....

thanks


 
Old February 16th, 2004, 10:18 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sample Oracle Function
**********************
-- Function takes table name as input parameter and returns the record count

CREATE OR REPLACE FUNCTION row_count (tab_name CHAR) RETURN INT AS
   rows INT;
BEGIN
   EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || tab_name INTO rows;
   RETURN rows;
END;


// The following is C# program to call the stored procedure function named row_count with one input parameter and gets the returned value

DbConn = new OleDbConnection("Provider=MSDAORA;Data Source=<source name>;User ID=<user name>;Password=<pwd>"); // Change infor for user
DbConn.Open(); // Open DB

DbCommand = new OleDbCommand("row_count",DbConn); // row_count name of stored procedure function
DbCommand.CommandType = CommandType.StoredProcedure;

// Return value type
DbCommand.Parameters.Add(new OleDbParameter("count",System.Data.OleDb.OleDbType .Integer));
DbCommand.Parameters["count"].Direction = ParameterDirection.ReturnValue;

// Input parameter type
DbCommand.Parameters.Add(new OleDbParameter("query",System.Data.OleDb.OleDbType .Char));
                DbCommand.Parameters["query"].Direction = ParameterDirection.Input;

// Assign input value
DbCommand.Parameters ["query"].Value = dr["DBQuery"];

// Execute the function
DbCommand.ExecuteScalar();

// Show the result
MessageBox.Show(DbCommand.Parameters["count"].Value.ToString());

I think this would help you.

Regards
Pradeep P:)

It is not how much we do,
but how much love we put in the doing.

-Mother Theresa





Similar Threads
Thread Thread Starter Forum Replies Last Post
call oracle function using oracle link server vl SQL Server 2000 1 July 12th, 2007 08:19 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
To call oracle stored procedure in vb6 krratnesh Pro VB 6 0 February 1st, 2006 10:26 AM
call oracle stored procedures from C# k_kosaraju ADO.NET 1 October 21st, 2004 03:03 AM
Error trying to call Oracle function in VB.NET lou_1 Pro VB.NET 2002/2003 0 January 13th, 2004 06:42 PM





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