Missing Key Error in MySQL Query
<p>I am working in C# and MySQl in VS2015 to Query my database. However, when I enter in a column name that is not of type Int or Datetime, the datareader returns an error.</p>

<p>However, there exists a column in the database that matches the string I enter as the database name. My Code: </p>

<pre><code>        string DateQuery = "SELECT timeStamp, amount, tax, name FROM log.transactions";

        MySqlCommand cmd3 = new MySqlCommand(DateQuery, connectionString);

        MySqlDataReader dataReader3 = cmd3.ExecuteReader();
</code></pre>

<p>On compilation this will return the error: "An unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll</p>

<p>Additional information: The given key was not present in the dictionary."</p>

<p>On dataReader3.</p>

<p>But if I remove the name(VarChar type) column from the query, it will compile and execute fine with timeStamp(DateTime) amount(Int), and tax(Int).</p>

<p>What dictionary is it referring to that doesn't contain a key? And why would it only affect types that are not Int or DateTime?</p>

<p>EDIT: Full Code posted below</p>

<pre><code> using System;
 using MySql.Data.MySqlClient;

 namespace TestApp
{
 class Program
{
    static void Main(string[] args)
    {
        Program generateReport = new Program();
        generateReport.Kickoff();
    }

    public void Kickoff()
    {
        string dbString = "server=XXXXXX;uid=XXXXXX;" + "pwd=XXXXX;database=XXXXX;";
        MySqlConnection connectionString = new MySqlConnection(dbString);

        connectionString.Open();
        Console.WriteLine("\nAttempting to connect to database...");
        if (connectionString.State.ToString() == "Open")
        {
            Console.WriteLine("Connection successful.");
        }
        else
        {
            Console.WriteLine("Connection failed. :(");
            return;
        }

        string DateQuery = "SELECT timeStamp, amount, tax, name FROM log.transactions";

        MySqlCommand cmd3 = new MySqlCommand(DateQuery, connectionString);
        MySqlDataReader dataReader3 = cmd3.ExecuteReader();
    }
}
</code></pre>

<p>}</p>

<p>EDIT: Stack Trace I believe:</p>

<pre><code>at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version String CharSetName)
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData41()
at MySql.Data.MySqlClient.NativeDriver.GetFieldMetaData()
at MySql.Data.MySqlClient.NativeDriver.ReadColumnMetadata(Int32 count)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior       behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
at TestApp.Program.Kickoff() in c:\users\Testuser\documents\visual studio 2015\Projects\TestApp\TestApp\Program.cs:line 42
at TestApp.Program.Main(String[] args) in c:\users\Testuser\documents\visual studio 2015\Projects\TestApp\TestApp\Program.cs:line 13
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
</code></pre>