0
obcon.cmd.CommandText = " select f_name + ' ' + m_name + ' ' + l_name from contact where type='" & ledcmbsrctype.Text & "'"
            obcon.con.Open()
            Dim dr As SqlDataReader
            dr = obcon.cmd.ExecuteReader
            While (dr.Read)
                ledcmbsrcitem.Items.Add(dr.Item(0))
            End While

'name is added to combo box and i want to get id for selected name.

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by adam_k
0

You need to change your code to something like:

obcon.cmd.CommandText = " select id, f_name + ' ' + m_name + ' ' + l_name as 'name' from contact where type='" & ledcmbsrctype.Text & "'"
            obcon.con.Open()
            Dim dr As SqlDataReader
            dr = obcon.cmd.ExecuteReader
ledcmbsrcitem.valuemember = "id"
ledcmbsrcitem.displaymember = "name"

            While (dr.Read)
                ledcmbsrcitem.Items.Add(dr.Item(0),dr.Item(1)) 
            End While

you get the id using ledcmbsrcitem.value and the displayed text with ledcmbsrcitem.text

Edited by adam_k: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.