title: C# Reusable Mysql Class
body: <p>I am having some issues with a class that I have created to perform different database commands.</p>
  
  <p>1st) The program is local ran, and will only run locally. It will only ever connect to the database on the localhost.</p>
  
  <p>Therefore I have a simple class setup, called databaseConnector that allows me to pass a string to it with the required Mysql query to perform the different functions.</p>
  
  <p>For instance.</p>
  
  <p>I use:</p>
  
  <pre><code>var db = new databaseConnector();
  db.Update("UPDATE * WHERE.....");
  </code></pre>
  
  <p>However, it seems if I ever want to use a different query, or another query, it's not working and throwing errors.</p>
  
  <p>For instance.</p>
  
  <pre><code>var db = new databaseConnector();
  db.Update("UPDATE * WHERE...");
  db.INSERT("INSERT INTO * WHERE.....");
  </code></pre>
  
  <p>Will give me an error on the insert execution. Any ideas why? I have resorted to creating it again. So I have to redo:</p>
  
  <pre><code>db = new databaseConnector();
  </code></pre>
  
  <p>to then use the Insert command.</p>
  
  <p>Here is an example of my insert function.</p>
  
  <pre><code>public void Insert(string query)
  {
  
  //open connection
  if (this.OpenConnection() == true)
  {
      //create command and assign the query and connection from the constructor
      MySqlCommand cmd = new MySqlCommand(query, connection);
  
      //Execute command
      cmd.ExecuteNonQuery();
  
      //close connection
      this.CloseConnection();
  }
  }
  </code></pre>
  
  <p>Now that I think about it. Should I call my db.openConnection() before doing it. Since when I initialize it in the first var db = new databaseConnection(), it's opening? And then in each function it's closing it, but only checking if it's open, instead of attempting to open, doing query, then closing.</p>