title: C# MySQL Query is not working
body: <p>Error message is,</p>
  
  <blockquote>
    <p>Connection must be valid and open. </p>
  </blockquote>
  
  <p>Is this code wrong? How can i solve the problem?</p>
  
  <pre><code>string strConn = "server = localhost; user = root; database = ****; port = 3306; password = ****; Charset = utf8";
  using (MySqlConnection conn = new MySqlConnection(strConn))
  {
      MySqlCommand insertCommand = new MySqlCommand();
  
      conn.Open();
  
      for (int i = 0; i &lt; 10; i++)
      {
          insertCommand.CommandText = "INSERT INTO master (col_name, col_code)" +
          " SELECT * from (select '" + _name[i] + "', '" + _code[i] + "') as tmp" +
          " WHERE NOT EXISTS (" +
          " SELECT col_code FROM master WHERE col_code = '" + _name[i] + "') limit 1;";
  
          insertCommand.ExecuteNonQuery();
      }
      conn.Close();
  }
  </code></pre>