Point
Point

Reputation: 1

Given key was not found in dictionary Visual C++ when grabbing data from MySQL

I'm currently working on a RFID project, and what I'm trying to do is to grab the value from MySQL local database that I had created. However, whenever I try doing so, it returns an exception that "Given key was not found in dictionary".

Inserted below is the code:

try 
{
    int identification = Int32::Parse(NUM->Text);
    String^ constr = "Server=127.0.0.1; Uid=root;Pwd=588588;Database=nationalid;CharSet=utf8;";
    MySqlConnection^ con = gcnew MySqlConnection(constr);
    MySqlCommand^  cmd = gcnew MySqlCommand("select * from userinfo WHERE identification=" + identification + "", con);
    con->Open();
    MySqlDataReader^ dr = cmd->ExecuteReader();
    while (dr->Read())
    {
        FN->Text = dr->GetString(1);
        MN->Text = dr->GetString(2);
        LN->Text = dr->GetString(3);
        N->Text = dr->GetString(4);
        B->Text = dr->GetString(5);
        A->Text = dr->GetString(6);
        TIN2->Text = dr->GetString(7);
    }
    con->Close();
}
catch (Exception^ ex)
{
    MessageBox::Show(ex->Message);
}

Upvotes: 0

Views: 42

Answers (0)

Related Questions