0

申し訳ありませんが、退屈している場合は。いくつかの検索エンジンで検索しましたが、結果が得られませんでした。とにかく、データベースがmysqlであるアプリで作業しています。データベース ラッパー クラスを作成したので、接続が既に開かれているかどうかを確認したいと考えています。私を助けてもらえますか?

             String^ constring = L"datasource=localhost;port=3306;username=root;password=pass;database=eps;";
             String^ my_query = L"select id from eps_users where usr = '" + this->user_name->Text + "' and psw = md5('" + this->pass_word->Text + "');";
             MySqlConnection^ conDatabase = gcnew MySqlConnection(constring);
             MySqlCommand^ cmd = gcnew MySqlCommand(my_query, conDatabase);
             MySqlDataReader^ myreader;
             try
             {
                 conDatabase->Open();
                 myreader = cmd->ExecuteReader();
                 int count = 0;
                 while (myreader->Read())
                 {
                     count = count + 1;

             }
             if (count == 1){
                 MessageBox::Show("Username And Password is correct.", "Success", MessageBoxButtons::OK,
                     MessageBoxIcon::Information);
                 this->Hide();
                 Form2^ f2 = gcnew Form2(constring);
                 f2->ShowDialog();
             }
             else{
                 MessageBox::Show("Username And Password is not correct.", "Error", MessageBoxButtons::OK,
                     MessageBoxIcon::Error);
                 // <del>
                 this->Hide();
                 Form2^ f2 = gcnew Form2(constring);
                 f2->ShowDialog();
                 // </del>
             }
         }
         catch (Exception^ ex)
         {
             MessageBox::Show(ex->Message);
         }
         conDatabase->Close();

if( conDatabase->HasBeenOpened()) { conDatabase->Open();} を確認する必要があります

4

1 に答える 1