title: MySQL causing fatal error after executing query with parameters
body: <p>I am creating a method that will execute a query with one or more parameters.</p>
  
  <p>Code:</p>
  
  <pre><code>public static IEnumerable&lt;T&gt; ExecuteQueryWithParameters&lt;T&gt;(string Query, string ConnectionString, string[] ParametersArray, string[] ValuesArray)
  {
      using (MySqlConnection Connection= new MySqlConnection(ConnectionString))
      {
          using (var cmd = new MySqlCommand(Query, Connection))
          {
              for (int i = 0; i &lt; ParametersArray.Length; i++)
              {
                  cmd.Parameters.AddWithValue(ParametersArray[i], ValuesArray[i]);
              }
  
              Connection.Open();
              return Connection.Query&lt;T&gt;(Query);
          }
      }
  }
  </code></pre>
  
  <p><code>Tempsave</code> table structure:</p>
  
  <pre><code>+------------------------------+
  |Id|Localization|Items|Quantity|
  +------------------------------+
  </code></pre>
  
  <p>How it works:</p>
  
  <p>When called, the method will receive 4 parameters:</p>
  
  <ol>
  <li>A <code>query</code> (example: <code>SELECT * FROM TempSave WHERE Localization  = @Localization</code>)</li>
  <li>A connection string (example: <code>server=localhost; database=wintestbeta;user=root; password=;</code>)</li>
  <li>A string array that contains one or more parameters (they look like this: <code>@Parameter1</code>)</li>
  <li>A string array that contains one ore more values</li>
  </ol>
  
  <p>Then it will create a new variable of type <code>MySqlConnection</code> called <code>Connection</code> with one parameter, the <code>ConnectionString</code>.</p>
  
  <p>After that it will create another variable type <code>MySqlCommand</code> called <code>cmd</code> with two parameters, one is the query and the other is the connection.</p>
  
  <p>Then it will enter a for loop with the size of the <code>ParametersArray</code> length, inside the for loop it will add a new parameter to <code>cmd</code> with two parameters, the <code>ParameterArray</code> with index equal to <code>i</code>, and a <code>ValueArray</code> with index also equal to <code>i</code>.</p>
  
  <p>Then it will open a connection and execute the query, what it receives from the query it will return.</p>
  
  <p>Code used to debug:</p>
  
  <pre><code>IEnumerable&lt;TempSave&gt; _CheckTemp;
  
  string Check_TempSave = "SELECT * FROM tempsave WHERE Localization=@Localization";
  
  string[] Parameters = new string[] { "@Localization" };
  string[] Values = new string[] { _Save.Localization };
  
  _CheckTemp = SQL.ExecuteQueryWithParameters&lt;TempSave&gt;(Check_TempSave, SQL.ConnectionString, Parameters, Values);
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>When executing the code when it reaches</p>
  
  <pre><code>return Connection.Query&lt;T&gt;(Query);
  </code></pre>
  
  <p>and causes the following error:</p>
  
  <blockquote>
    <p>Fatal error encountered during command execution.</p>
  </blockquote>
  
  <p>When debugging I checked and both parameters and values only have one value that is:</p>
  
  <pre><code>@Localization
  Counter,1
  </code></pre>