如何选择有界组合框值并将其值显示到标签文本中 [英] How to select an bounded combo box value and display its value into an Label Text

查看:90
本文介绍了如何选择有界组合框值并将其值显示到标签文本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ComboBox1,它受EmpId限制,这也是主键..当我使用代码时



private void comboBox1_SelectedIndexChanged(object sender,EventArgs e )

{

label5.Text = comboBox1.DisplayMember;

}



它给出了一个错误 -



列'EmpId'被限制为唯一的。价值'Emp008'已经存在。



我的问题是如何选择有界值并将其显示在标签文本中..

I have an ComboBox1 which is bounded by EmpId which is an primary key also.. when i used the code

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label5.Text = comboBox1.DisplayMember;
}

it gives an error-

Column 'EmpId' is constrained to be unique. Value 'Emp008' is already present.

My question is How to select that bounded value and display it into an Label text..

推荐答案

private void bind()

{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [AttendanceManagmentSystem.Properties.Settings.Cons1 ] .ConnectionString);

con.Open();

SqlDataAdapter da = new SqlDataAdapter(从EmpDetail中选择EmpId,con);

DataTable dt = new DataTable();

da.Fill(dt);

comboBox1.DisplayMember =EmpId;

comboBox1。 ValueMember =EmpId;

comboBox1.DataSource = dt;

con.Close();

}

private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)

{

label5.Text = comboBox1.Text;

}
private void bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AttendanceManagmentSystem.Properties.Settings.Cons1"].ConnectionString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select EmpId from EmpDetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DisplayMember = "EmpId";
comboBox1.ValueMember = "EmpId";
comboBox1.DataSource = dt;
con.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label5.Text = comboBox1.Text;
}


这篇关于如何选择有界组合框值并将其值显示到标签文本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆