You want to get rid of the parameters only at the very end of their use, including during the request (and, possibly, when reading the results):
using (OracleConnection conn = new OracleConnection(connectionstring)) { conn.Open(); using (OracleCommand cmd = new OracleCommand(sql, conn)) { cmd.BindByName = true; using (OracleParameter param1 = new OracleParameter("p1", OracleDbType.Int32, System.Data.ParameterDirection.Input)) using (OracleParameter param2 = new OracleParameter("p2", OracleDbType.Varchar2, System.Data.ParameterDirection.Input)) { param1.Value = int.Parse(value1); cmd.Parameters.Add(param1); param2.Value = value2; cmd.Parameters.Add(param2); using (OracleDataReader dr = cmd.ExecuteReader()) {
Note that you can put multiple using statements in a string. This is because, like the if ,
- The A
using statement is considered a simple statement (even with a block); and - The
using statement can accept either a block or the statement below it.
Platinum azure
source share