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
|