Prüfen Sie, ob Sie ein combobox-Wert ausgewählt wurde, und C# .net

Ich versuche, meine Anwendung besser durch die Behandlung von Ausnahmen. Ich habe ein Formular, bei dem, wenn alle Felder, die nicht ausgefüllt werden, dann zeigen Sie eine Meldung an den Benutzer. Folgende ist, was ich versucht haben, aber selbst wenn Sie alle Felder ausgefüllt haben, es immer noch nicht lassen Sie mich vorbei.

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();
}

InformationsquelleAutor anonymous | 2013-05-06

Schreibe einen Kommentar