I'm trying construct a MySQL query in my C# application, I'm wondering if it's possible to use OR statement in a MySQL parameters.
I have a list of names, and I want to check and see what are the names that exist in the database already. Here's a short example
List<string> names = new List<string> {"adam", "bob", "cathy"}; //actual list is much longer
MySqlConnection connection = getAndOpenConnection();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Employees WHERE name = @names";
command.Parameters.Add(new MySqlParameters("@names", String.Format("names = {0}", String.Join(names, " or name = ")))); //is this line legal?
My original idea is to construct the command text this way:
command.CommandText = String.Format("SELECT * FROM Employees WHERE name = '{0}'", String.Join(names, "' or name = '"))
The code will give me the correct command text I want, but I really want to prevent SQL injection.
Can someone please help me out on how to construct the MySqlCommand properly?