Here is the way I try to execute an sql command:
List<int> idsToDelete = new List<int>() { 1, 2, 3 };
string sqlDel = @"DELETE FROM products WHERE product_id IN (:idsToDelete)";
using (OracleCommand cmdDel = new OracleCommand(sqlDel, connexion))
{
cmdDel.Parameters.Add("idsToDelete", idsToDelete.ToArray());
cmdDel.ExecuteNonQuery();
}
I get the following exception:
Unable to cast an object form type 'System.Int32[]' to type 'System.IConvertible'.
I get the same exception with the following command:
string sqlDel = @"DELETE FROM products WHERE product_id IN :idsToDelete";
I ther a proper way to set a mutli value parameter for an IN condition? I don't want to format the command string, because it has to be reusable.
string sqlDel = $@"DELETE FROM products WHERE product_id IN ({string.Join(", ", idsToDelete)})";or you have to create a parameter for each item inidsToDelete