c# – oracle: Named parameters or their order?

Question:

don't even know where to start … the .net program works with oracle. named parameters are used to transfer data. the work has been going on for several years. once everything worked clearly, but now it turned out that the names of the parameters do not matter, but their order does. tell me where to dig

stored procedures are accessed, parameters are passed in the standard way:

using (OracleCommand cmd = GetConnection().CreateCommand())
{
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.CommandText = "Owner.Package.Procedure";
            OracleParameter p1 = new OracleParameter();
            p1.OracleDbType = OracleDbType.Decimal;
            p1.Direction = ParameterDirection.Input;
            p1.ParameterName = "param1";        
            OracleParameter p2 = new OracleParameter();
            p2.OracleDbType = OracleDbType.Decimal;
            p2.Direction = ParameterDirection.Input;
            p2.ParameterName = "param2";        
            cmd.Prepare();
            cmd.ExecuteNonQuery();
}

how it should be done: when you change the order of the parameters, everything should work correctly.

as now: if you swap the parameters (and their type is the same), then the procedure will be executed, but with incorrect data.

Answer:

everything is simple, there is a special property for this

cmd.BindByName = true;

Scroll to Top