title: How to create a Method in C# that will allow me to prepare any insert/update statement?
body: <p>I am trying to write a small class that will help me to connect to MySQL server using C# and winforms. 
  I wrote the connection that would start and close the connection.</p>
  
  <p>What I am looking to do here is to create a method in this class to allow me to pass a query and values "in array" and the method will auto prepare the query for me.</p>
  
  <p>so instead of writing a method or a code for every INSERT/UPDATE query like so...</p>
  
  <pre><code>    MySqlCommand command = connection.CreateCommand();
      command.CommandText = "INSERT INTO mytable(a,b,c,d)VALUES (?, ?, ?, ?)";
      command.Parameters.AddWithValue("?", array_val1);
      command.Parameters.AddWithValue("?", array_val2);
      command.Parameters.AddWithValue("?", array_val3);
      command.Parameters.AddWithValue("?", array_val4);
      connection.Open();
      command.ExecuteNonQuery();
  </code></pre>
  
  <p>I would like to have a method  where I Can pass the query and the values and it will auto prepare that statement for me.</p>
  
  <p>something like this</p>
  
  <pre><code>//Call the Method
      processQuery("INSERT INTO mytable(a,b,c,d)VALUES (?, ?, ?, ?)", array(1,2,3,4));
  //The new Method
      public processQuery(string sqlStr, array values){
  
          MySqlCommand command = connection.CreateCommand();
          command.CommandText = sqlStr;
          command.Parameters.AddWithValue("?", array_val1);
          command.Parameters.AddWithValue("?", array_val2);
          command.Parameters.AddWithValue("?", array_val3);
  ....
  ....
  ....
  ....
          command.Parameters.AddWithValue("?", array_val_SIZE_OF_ARRAY);
          connection.Open();
          command.ExecuteNonQuery();
  
      }
  </code></pre>