hi,
set the datatextfield property to the name of the course
set the datavaluefield property to the id as shown below
ddlist.DataTextField = "coursename"
ddlist.DataValueField = "course_id"
to access the id use the following code
ddlist.SelectedItem.Value
using the above code only the course name is displayed and internally u get the course id
hope this helps u
Cheers!
Asha S :)
Thnx .. but as i said , i am using ComboBox not list box .. .. sorry , i didn't understand it .. have a look at my code :
' this sub to get the database from the SQL and fill it into the combo box.
Private Sub KG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As New SqlConnection
cn.ConnectionString = "Data Source=PC100-042295F4E;" & "Trusted_connection=yes;" & "initial Catalog=Client;"
Dim da As New SqlDataAdapter("SELECT course_name as NAME, course_id FROM Courses WHERE (course_category = 5)", cn)
Dim dt As New DataTable
loading = True
Try
da.Fill(dt)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cmbKg.DataSource = dt
cmbKg.DisplayMember = ("NAME") 'how to display the full name ? '& " " & "Emp_Sname" & " " & "Emp_Fname")
cmbKg.ValueMember = "course_id"
loading = False
End Sub
' now my code to fill from the combo box into another table in the data bas as below :
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
cmd.CommandText = "Insert into Clients_Tb (Course_id, .... values ( ??? here what shall i say !!?