這是問題所在。我試圖執行一個查詢,並在connection.Open
處拋出異常。奇怪的是,在同一個應用程序中,我正在執行「選擇」查詢並且它工作正常。但是當我執行「更新」查詢時,它會拋出這個無法連接到任何指定的MySQL主機錯誤。一直堅持這一點。有人可以發現我出錯的地方嗎?無法連接到任何指定的MySQL主機
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
timerEnabled = 1;
}
connection.Open();
//update the settings to the database table
MySqlCommand command = connection.CreateCommand();
command.CommandText = "update Admin_Settings set Difficulty='" + comboBox3.Text + "'," + "NoOfQuestions='" + comboBox4.Text + "'," + "NoOfChoices='" + comboBox5.Text + "'," +
"Subject='" + comboBox8.Text + "'," + "Timer='" + comboBox2.Text + "," + "TimerEnabled=" + timerEnabled + "," + "TimerType='" + comboBox1.Text + "'";
command.ExecuteNonQuery();
MessageBox.Show("Settings updated");
}
你的問題需要更多的信息。當connection.Open();'執行?似乎是一個可能的原因。 – evanmcdonnal 2013-02-27 22:56:59