CREATE OR REPLACE FUNCTION func_RetrieveCount
RETURN NUMBER
IS
intRecordCount NUMBER;
BEGIN
SELECT COUNT(*) INTO intRecordCount FROM Products;
RETURN intRecordCount;
END;
/
private void btnRetrieveCount_Click(object sender, EventArgs e)
{
string _connstring = "Data Source=localhost/NEWDB;User
Id=EDZEHOO;Password=PASS123;";
try
{
OracleConnection _connObj = new OracleConnection(_connstring);
_connObj.Open();
OracleCommand _cmdObj = _connObj.CreateCommand();
_cmdObj.CommandText = "func_RetrieveCount";
_cmdObj.CommandType = CommandType.StoredProcedure ;
//Declare the return parameter
OracleParameter _retValueParam = new OracleParameter();
_retValueParam.ParameterName = "Any_name";
_retValueParam.OracleDbType = OracleDbType.Int32;
_retValueParam.Direction = ParameterDirection.ReturnValue;
_cmdObj.Parameters.Add(_retValueParam);
_cmdObj.ExecuteNonQuery();
MessageBox.Show("The return value is :" + _retValueParam.Value.ToString());
_connObj.Close();
_connObj.Dispose();
_connObj = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}