日期:2014-05-17  浏览次数:21024 次

combox条件选中的问题
本帖最后由 bulls5988 于 2013-11-28 07:56:36 编辑
FORM1用来修改DataGridView里选中的ID内容,里面有几个文本框和一个combox1,表(staff_card)是存放卡资料的,其中有一个字段(card_type)是卡类型;比如“会员卡”,FORM1_LOAD的时候遍历了一张专门存放卡类型的表(feecard_type),里面有“金卡”、“会员卡”、“员工卡”等。我在FORM1_Load的时候已经把feecard_type里的所有卡类型遍历进combox1里了。

要在FORM1_LOAD的时候,如果被修改的这条记录中卡类型,为“会员卡”,那么combox1中的"会员卡"同时被选中。 //我修改的记录中卡类型内容和combox1中内容相同时,combox1中的这个条记录被选中。


//已经把所有feecard_type中所有的卡类型遍历进了combox1了
string card_class_sql = "select * from feecard_type_card order by card_id asc";
            SqlConnection class_conn = new SqlConnection(fee_conn.sql_conn());
            DataSet combox = new DataSet();
            class_conn.Open();
            SqlDataAdapter mycmd = new SqlDataAdapter(card_class_sql, class_conn);
            mycmd.Fill(combox, "ds");
            class_conn.Close();

            comboBox1.DataSource = combox.Tables[0];
            comboBox1.DisplayMember = "card_name";
            comboBox1.ValueMember = "card_fee";
            comboBox1.SelectedIndex = 0;
            
            fee_id = int.Parse(park_fee_staffeditcard.staff_id);
            string e_sql = "select * from staff_card where 
staff_value_id = '" + fee_id + "'";
//在staff_card表中根据上一个窗体传递的ID查找卡资料
            SqlConnection e_conn = new SqlConnection(fee_conn.sql_conn());
            SqlCommand e_select = new SqlCommand(e_sql, e_conn);
try
            {
                e_conn.Open();
            }
            catch (System.Exception)
            {
                MessageBox.Show( MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SqlDataReader e_rs = e_select.ExecuteReader();
            {