Click here to Skip to main content
15,921,530 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have table named employee(empID,EmpName,EmpSalary)
I want to bind 'EmpName' column to combo box on my form. how many ways.. I can do this.

What I have tried:

I am trying to bind data tables column containt to with combo box.
Posted
Updated 25-Feb-16 17:45pm
Comments
CHill60 25-Feb-16 12:16pm    
What have you actually tried?
Set the ComboBox DataSource to the datatable and the DisplayMember to be "EmpName"

1 solution

C#
objdbconn.OpenConn()
       msSQL = " select a.employee_gid,concat(user_firstname,' ',user_lastname) as employee_name from hrm_mst_temployee a " & _
               " inner join adm_mst_tuser b on a.user_gid=b.user_gid order by user_firstname asc "
       ds_data = objdbconn.GetDataSet(msSQL, "hrm_mst_temployee")
       cboEmployee.DataSource = ds_data
       cboEmployee.DataMember = "hrm_mst_temployee"
       cboEmployee.DataTextField = "employee_name"
       cboEmployee.DataValueField = "employee_gid"
       cboEmployee.DataBind()
       cboEmployee.Items.Insert(0, "--Select--")
       cboEmployee.SelectedIndex = -1
       ds_data.Dispose()
       objdbconn.CloseConn()
 
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