Home » Infrastructure » Windows » VS, ODAC, Procedures, & SELECT statement (12C)
|
|
|
|
|
|
|
|
Re: VS, ODAC, Procedures, & SELECT statement [message #654836 is a reply to message #654433] |
Mon, 15 August 2016 14:06   |
 |
derrellgore
Messages: 20 Registered: July 2016
|
Junior Member |
|
|
Just got back to this...thought I would share what I came up with. After looking at many examples...some of them being very bizarre and way to much work...I narrowed it down to exactly what I needed to retrieve data using a stored procedure. I have found most Oracle documentation gives you way more information than you need. It is sometimes not easy to pick out exactly what you do need.
Hope this helps someone out. I felt like I spent way to much time looking for an answer on this one. I know it took me a few tries to get it to work.
Stored Procedure...
create or replace PROCEDURE SPVARIANCE_GETROUTE
(
p_YearMonth VARCHAR2,
p_Cycle int,
p_RefCursor OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN p_RefCursor FOR
SELECT DISTINCT Route
FROM HWL_Variance
WHERE YearMonth = p_YearMonth AND Cycle = p_Cycle
ORDER BY Route;
END SPVARIANCE_GETROUTE;
C# Procedure...
public static List<HWL_Variance> GetRoute(string yearMonth, int cycle)
{
List<HWL_Variance> routeList = new List<HWL_Variance>();
OracleConnection connection = HWLOracleDB.GetConnection();
OracleCommand selectCommand = new OracleCommand("SPVARIANCE_GETROUTE", connection);
selectCommand.CommandType = CommandType.StoredProcedure;
selectCommand.Parameters.Add(new OracleParameter("p_YearMonth", yearMonth));
selectCommand.Parameters.Add(new OracleParameter("p_Cycle", cycle));
OracleParameter p_RefCursor = new OracleParameter();
p_RefCursor.OracleDbType = OracleDbType.RefCursor;
p_RefCursor.Direction = System.Data.ParameterDirection.Output;
selectCommand.Parameters.Add(p_RefCursor);
try
{
connection.Open();
OracleDataReader reader = selectCommand.ExecuteReader();
while (reader.Read())
{
HWL_Variance route = new HWL_Variance();
route.Route = Convert.ToInt32(reader["Route"]);
routeList.Add(route);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
connection.Close();
}
return routeList;
}
|
|
|
|
|
Goto Forum:
Current Time: Sat Jun 07 17:40:08 CDT 2025
|