Click here to Skip to main content
15,881,654 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..
Posted

1 solution

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;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900