Is there a way to add a parameter to an IN clause using System.Data.OracleClient.
For example:
string query = "SELECT * FROM TableName WHERE UserName IN (:Pram)"; OracleCommand command = new OracleCommand(query, conn); command.Parameters.Add(":Pram", OracleType.VarChar).Value = "'Ben', 'Sam'";
You can wrap it in OracleCommandExtension method:
public static class OracleCommandExtension { public static OracleCommand AddParameterCollection<TValue>(this OracleCommand command, string name, OracleType type, IEnumerable<TValue> collection) { var oraParams = new List<OracleParameter>(); var counter = 0; var collectionParams = new StringBuilder(":"); foreach (var obj in collection) { var param = name + counter; collectionParams.Append(param); collectionParams.Append(", :"); oraParams.Add(new OracleParameter(param, type) { Value = obj }); counter++; } collectionParams.Remove(collectionParams.Length - 3, 3); command.CommandText = command.CommandText.Replace(":" + name, collectionParams.ToString()); command.Parameters.AddRange(oraParams.ToArray()); return command; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With