把数据库表的某一列的数据添加到comboBox中

时间:2022-02-21 03:38:38
       public void update_cardName()
        {
            string conStr = "server=(local);database=个人财务管理; Integrated security=true;";
            SqlConnection con = new SqlConnection(conStr);
            string sqlStr = "select 卡号尾数 ,银行卡名称 from 银行卡信息;";
            try
            {
                con.Open();
                DataSet ds1 = new DataSet();
                DataSet ds2 = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(sqlStr, con);
                da.Fill(ds1);
                da.Fill(ds2);
                comboBox1.DataSource = ds1.Tables[0].DefaultView;
                comboBox1.DisplayMember = "卡号尾数";
                comboBox2.DataSource = ds2.Tables[0].DefaultView;
                comboBox2.DisplayMember = "卡号尾数";
                con.Close();
            }
            catch (Exception ex11)