In the MySQL .NET provider, you can use named parameters in the syntax:
?parametername
Now, I'm trying to create a named parameter for a parameter that will be used in an 'IN' list, e.g. :
select * from mytable where id in (?ids)
How can I use a named parameter with this, if I use varchar, it will add quotes before and after the list, ie.:
If I pass the value of the parameter using varchar:
cmd.Parameters.Add("?ids", MySqlDbType.Varchar).Value = ids; // ids is a string which contains the ids separated by commas, e.g. 1, 2, 3 .. etc
the query will be executed like this:
select * from mytable where id in ('1, 2 ,3')
Of course this will throw an error, how can I pass a named parameter without getting the quotes, this is the way it should be executed:
select * from mytable where id in (1, 2 , 3)
Is there any workaround for this? I'm currently using String.Format() but would like to use a named parameter, is this possible some how?
P.S. I'm only using plain text statements, no sproc, so none of this is going to be passed to an sproc (just in case you think it's not possible because sprocs don't accept arrays)