Hi,
I have inherited a function in an ASP.NET (C#) application where the author used the Microsoft.Practices.EnterpriseLibrary.Data library
, but I have been asked to change it so that it uses System.Data.OracleClient
. This function uses a stored procedure form a database. itemName
, and openDate
are string parameters that the function takes in. PKG_AUCTION_ITEMS.IsAuctionItem
is the stored procedure function name.
Here is the code that I received:
string result = String.Empty;
Database db = DatabaseFactory.CreateDatabase("OraData");
using (DbCommand cmdDB = db.GetStoredProcCommand("PKG_AUCTION_ITEMS.IsAuctionItem"))
{
db.AddInParameter(cmdDB, "vItemName", DbType.String, itemName);
db.AddInParameter(cmdDB, "vOpenDate", DbType.String, openDate);
db.AddParameter(cmdDB, "ret", DbType.String, 2, ParameterDirection.ReturnValue, false, 0, 0, null, DataRowVersion.Current, null);
db.ExecuteNonQuery(cmdDB);
result = cmdDB.Parameters["ret"].Value.ToString();
}
Here is my code:(connstr
is the connection string)
string result = String.Empty;
OracleConnection conn = new OracleConnection(connstr);
OracleCommand cmd = new OracleCommand("PKG_AUCTION_ITEMS.IsAuctionItem",conn);
myCmd.CommandType = CommandType.StoredProcedure;
using (myCmd)
{
myCmd.Parameters.AddWithValue("vItemName", itemName);
myCmd.Parameters.AddWithValue("vOpenDate", openDate);
myCmd.Parameters.AddWithValue("ret", ???);
myCmd.ExecuteNonQuery();
result = myCmd.Parameters["ret"].Value.ToString();
}
I do not understand what the difference between AddInParameter and AddParameter is, and what this line does:
db.AddParameter(cmdDB, "ret", DbType.String, 2, ParameterDirection.ReturnValue, false, 0, 0, null, DataRowVersion.Current, null);
Am I on the right track? Can anyone please help? Thanks