title: Using c# Method to execute SQL Query
body: <p>What is the best technique to run SQL query that then displays that information on a Winform textbox whilst avoiding repeat code? With My basic understanding of c#, I have created the below method but it requires me to add the same text twice at the end. </p>
  
  <pre><code>  public MySqlDataReader RunQueryTextField5(string query, Control c1, string s1, Control c2, string s2, Control c3, string s3, Control c4, string s4, Control c5, string s5)
      {
          MySqlConnection conDataBase = new MySqlConnection(connString);
          MySqlCommand cmdDatabase = new MySqlCommand(query, conDataBase);
          MySqlDataReader myReader;
  
  
          conDataBase.Open();
          myReader = cmdDatabase.ExecuteReader();
  
  
          while (myReader.Read())
          {
              c1.Text = (myReader[s1].ToString());
              c2.Text = (myReader[s2].ToString());
              c3.Text = (myReader[s3].ToString());
              c4.Text = (myReader[s4].ToString());
              c5.Text = (myReader[s5].ToString());
  
          }
  
          conDataBase.Close();
          return myReader;
      }
  </code></pre>
  
  <p>// is how I call it if the other query but as you can see since this one only has four fields I pass on the last fields twice. </p>
  
  <pre><code>RunQueryTextField5("SELECT DISTINCT * FROM `Course qualification Prices` WHERE `qualification name` = '" + cboQualificationName.Text + "' AND `delivery mode` = '" + cboTrainingDeliveryMode.Text + "' ",
  
  
                      txtTrainingQualifcationCode, "course unit code",
         txtTrainingQualificationPrice, "Price",
        txtTrainingMaterialsHyperLink, "Support Materials Hyperlink",
                txtTrainingMaterialsHyperLink, "Support Materials Hyperlink",
                txtTrainingMaterialsHyperLink, "Support Materials Hyperlink");
  
  
              }
  </code></pre>