我试图通过处理异常来使我的应用程序更好。我有一个表单,如果所有字段都没有完成,那么会向用户显示一个消息框。以下是我尝试过的,但即使所有字段都已完成,它仍然不会让我通过。
if (textBox1.Text == null || comboBox3.SelectedValue == null ||
comboBox4.SelectedValue == null ||
comboBox5.SelectedValue == null || comboBox8.SelectedValue == null)
{
MessageBox.Show("Please make sure you don't have any missing fields");
}
else
{
connection.Open();
//update the settings to the database table
MySqlCommand command = connection.CreateCommand();
// Insert into table_name values ("","name","1")
command.CommandText = @"insert into CustomTests values ('','" + textBox1.Text + "'," + Convert.ToBoolean(checkBox1.CheckState) + ",'" + comboBox3.Text + "'," + comboBox4.Text + "," + comboBox5.Text + ",'" + comboBox8.Text + "'," + comboBox2.Text + "," + Timer_Enabled + ",'" + comboBox1.Text + "')";
command.ExecuteNonQuery();
}