Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 30th, 2004, 02:51 AM
Registered User
 
Join Date: Jan 2004
Location: Beirut, , Lebanon.
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


Reply With Quote
  #2 (permalink)  
Old February 16th, 2004, 10:18 AM
Friend of Wrox
 
Join Date: Feb 2004
Location: Bangalore, Karnataka, India.
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
Reply With Quote
Reply


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
call oracle function using oracle link server vl SQL Server 2000 1 July 12th, 2007 09: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 04: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



All times are GMT -4. The time now is 09:24 AM.


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