这是问题所在。我正在尝试执行查询及其抛出和异常connection.Open
。奇怪的是,在同一个应用程序上,我正在执行“选择”查询,它工作正常。但是当我执行“更新”查询时,它会抛出这个无法连接到任何指定的 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");
}