'Private Sub ComboBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ComboBox1.SelectionChanged
    '    Dim cmd As New SqlClient.SqlCommand
    '    Dim tbl As New DataTable
    '    Dim da As New SqlClient.SqlDataAdapter
    '    Dim code As Integer
    '    Dim ds As New DataSet
    '    Dim sql_empid As String = cmbaaa.SelectedValue.ToString


    '    Try
    '        cn.Open()

    '       

    '        sql_empid = "select * from EmMaster where EmMaster_EmpName  Like %sql_empid"

    '        da = New SqlDataAdapter(sql_empid, cn)
    '        da.Fill(ds, "EmMaster")
    '        tbl = ds.Tables(0)


    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '    Finally
    '        cn.Close()
    '    End Try
    'End Sub

hii frnds i work in vb.net windows apps now i use combobox to disply list of name but in combobox search the item when i type any letter Ex. i type A in combobox then dispaly all name in use A .
please solve my problem.

Thanks & Regards

Why is everything commented? When you declare sql_empid, you assign a value from another control, cmbaaa. Did you want to assign from Combo1 instead?

After opening the connection, you reassign sql_empid with a totally different string, referencing the initialized value. This is not generally considered good form; use seperate variables for the selected value and the SQL string, as this can make it harder to debug your code.

In SQL, to reference a field in a table, use a . to separate the table and field, not an underscore.

Pay attention to the details and try to follow best practices to avoid these kinds of problems.

Edited 8 Months Ago by Nutster: Improve spacing. More detail.

Your codes are quite perfect.
your problem arises for the line Dim sql_empid As String = cmbaaa.SelectedValue.ToString.
When you are typing "A" sql_empid stores the value A and it displays all values which are using A.
So you can use

Dim sql_empid As String = cmbaaa.Items(cmbaaa.SelectedIndex)
This article has been dead for over six months. Start a new discussion instead.