将数据从mysql插入cli列表框

时间:2018-12-25 22:23:31

标签: mysql .net winforms

listbox is empty我想从我的SQL中获取数据并将其插入到列表框表单中,但我不能。通过编译列表框为空。我怎么了?

private: System::Void listBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e)
        {
            String^ SQLconnection = "Server = localehost; Uid = root; Password = pass123; Database = details";
            MySqlConnection^ conn = gcnew MySqlConnection(SQLconnection);
            MySqlCommand^ cmd = gcnew MySqlCommand("SELECT * FROM details.material;", conn);
            MySqlDataReader^ reader;

        try
        {
            conn->Open();
            reader = cmd->ExecuteReader();
            while (reader->Read())
            {
                listBox1->Text +=(reader->GetInt32(0));
            }


        }catch (Exception^ ex)
        {
            MessageBox::Show(ex->Message);
        }

        }

0 个答案:

没有答案