Don't leave yourself open to security issues, this is really not a good idea in my opinion. I would personally avoid the use of dynamic sql and just write out a different query for each column you need to edit. Check out this thread if you are dead set on this approach.
Like this...
string pas;
using (MySqlConnection cnn = new MySqlConnection(connectionString))
{
string likvidavimas = string.empty;
if (pas == "Table1")
{
likvidavimas = "DELETE FROM [Table1] WHERE ID=@ID";
}
else if (pas == "Table2")
{
likvidavimas = "DELETE FROM [Table2] WHERE ID=@ID";
}
likvidavimas.Parameters.AddWithValue("@ID", ID);
cnn.Open();
using (MySqlCommand cmd = new MySqlCommand(likvidavimas, cnn))
{
cmd.ExecuteNonQuery();
}
}
Also, I always suggest using using
to help clean up your resources at the end of execution. Not sure what MySqlCommand
will be, but if it is IDisposable
I'd say wrap it as well.