2011年4月19日火曜日

データの表示(参照)


private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
 String^connStr = "server=localhost;Database=test;Uid=root;Pwd=password";
 MySqlConnection^ conn = gcnew MySqlConnection(connStr);
 try{
  textBox1->AppendText("Connecting to MySQL..." + "\r\n");
   conn->Open();

  String^ sql = "SELECT name, age FROM `sampleTable`";
  MySqlCommand^ cmd = gcnew MySqlCommand(sql, conn);
  
  MySqlDataReader^ rdr = cmd->ExecuteReader();

  while (rdr->Read()){
   textBox1->AppendText(rdr[0] + " -- " + rdr[1] + "\r\n");
  }
  rdr->Close();
 }catch (Exception^ e){
  textBox1->AppendText(e->ToString());
 }
 conn->Close();
 textBox1->AppendText("Done." + "\r\n");
}
passwordはそれぞれ書き変えて下さい。

0 件のコメント:

コメントを投稿