Public Sub getconcom_name()
    ledcmbsrcitem.Items.Clear()
    Try
        obcon.cmd.CommandText = "select con_id,f_name + ' ' + m_name + ' ' + l_name as 'name' from contact where type='company'"
        obcon.con.Open()
        Dim dr As SqlDataReader
        dr = obcon.cmd.ExecuteReader
        Dim oDataSet As New DataSet()

        While (dr.Read)
            ' MsgBox(dr.Item(0))
            ledcmbsrcitem.Items.Add(dr.Item(1))
        End While
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        obcon.con.Close()
    End Try
End Sub



Public Sub getconcom_id()
    Try
        obcon.cmd.CommandText = "select con_id from contact where f_name + ' ' + m_name + ' ' + l_name ='" & ledcmbsrcitem.Text & "'"
        obcon.con.Open()
        ' obcon.cmd.Connection = obcon.con
        concom_id = obcon.cmd.ExecuteScalar
        MsgBox(concom_id)
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        obcon.con.Close()
    End Try
End Sub

'here problem is if same name available i cant get its id,it always get first compared name's id.

Thats because you are using executeScalar() which returns one row. Using a reader will return all rows that meet the criteria. You should be asking yourself if the exact same data should be in the database twice. If the only thing that changes is the id column you have redundency is your database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.