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

来源:互联网 发布:java自学看什么书 编辑:程序博客网 时间:2024/06/06 04:30
       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)
            {
                MessageBox.Show(ex11.Message);
            }
        }
原创粉丝点击