如何在选择索引更改时验证组合框?

时间:2016-09-01 12:06:01

标签: c# winforms

    private void button1_Click(object sender, EventArgs e)
    {
        for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
        {
            if (comboBox1.SelectedItem.ToString() == ds.Tables[0].Rows[x].ItemArray[0].ToString() &&
                comboBox2.SelectedItem.ToString() == ds.Tables[0].Rows[x].ItemArray[1].ToString())
            {

                if (comboBox3.SelectedItem.ToString() == ds.Tables[0].Rows[x].ItemArray[2].ToString())
                {
                    MessageBox.Show("This Items is Already there");
                    // comboBox3.SelectedItem = null;
                    clear1();
                    return;
                }

            }
            cm = new SqlCommand("insert into covers(MobileBrand,MobileModel,Type) values('" + comboBox1.Text.ToString() + "','" + comboBox2.Text.ToString() + "','" + comboBox3.SelectedItem.ToString() + "')", cn);
            cm.ExecuteNonQuery();
            MessageBox.Show("Data Inserted");
            clear1();
            fetch();
            return;
        }

    }

0 个答案:

没有答案