Unfortunately, SQL parameters aren't resolved that way, in other words, the backend doesn't just build a safe-string replacing each parameter with its value. Instead, you'll have to dynamically build a parameter list:
cmd.CommandText = @"select column_name, table_name from information_schema.columns where table_name in (@p1, @p2, @p3)"; // This can be built dynamically
And then add each parameter:
cmd.Parameters.AddWithValue("@p1", "tableOne");
cmd.Parameters.AddWithValue("@p2", "tableTwo");
cmd.Parameters.AddWithValue("@p3", "tableThree");
You could of course add these parameters in a loop if the number was unknown until runtime:
for(var i = 0; i < myParams.length; i++)
{
cmd.Parameters.AddWithValue("@p" + i.ToString(), myParams[i]);
}
If your list of tables were stored in an enum
, or you could escape them or validate them with a regular expression, it would also be fairly safe to just build the raw SQL yourself and not use parameters at all.
This is, of course, one of the big reasons I use PostgreSQL; native support for arrays.