Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Experts

I am trying to show concatenated string into autocomplete textbox
when user start typing it will search by last name. query will look into database for full name contains ... and in autosuggestion it will show full name, company

.
if I just search by last_name
and put last_name MyCollection.Add(reader("last_name").ToString())

It shows result
however following code shows nothing

here is my code

can anyone please suggest me how to resolve this ?
VB
Dim strauto As String

       Dim name As String
       name = Trim(txtCompanyKeyContacts.Text)
       If name = "" Then Exit Sub
       Dim cnString As String = ConfigurationManager.ConnectionStrings("dbcon").ConnectionString
       Dim con As New SqlConnection(cnString)

       Using con
           strauto = "SELECT (FULL_NAME + ',' + Company + ',' + Status) as contact  FROM name where FULL_NAME like '%" & Replace(name, "'", "''") & "%' "
           'SELECT last_name,FULL_NAME + ',' + Company + ',' + Status as contact FROM name"
           con.Open()
           Dim cmd As New SqlCommand(strauto, con)

           Dim reader As SqlDataReader = cmd.ExecuteReader()
           Dim MyCollection As New AutoCompleteStringCollection()

           If reader.HasRows = True Then
               While reader.Read()


                   ' MyCollection.Add(reader("FULL_NAME + ',' + Company + ',' + Status").ToString())
                   MyCollection.Add(reader("contact").ToString())
               End While
           End If

          

           txtCompanyKeyContacts.AutoCompleteCustomSource = MyCollection
           con.Close()
       End Using
Posted
Comments
Suvendu Shekhar Giri 29-Oct-15 2:03am    
Everything looks fine. Make sure that your query returns a result.
dash2020 29-Oct-15 5:27am    
thanks for confirming ..I've checked records by putting msgbox ..reader gives me expected result.

Im calling this proc in the formload and on textbox change..

tried to call on key press/ keydown and keyup also but nothing is working
Naveen.Sanagasetti 29-Oct-15 2:58am    
request you to debug the code to fix this type of issues..
dash2020 29-Oct-15 5:28am    
thanks for confirming ..I've checked records by putting msgbox ..reader gives me expected result.

Im calling this proc in the formload and on textbox change..

tried to call on key press/ keydown and keyup also but nothing is working

1 solution

Hi All
Couldnt find solution so used combobox instead of textbox.
if you got to know the problem then please post the solution. even if I've chosen a different path I'd like to know the solution for this problem
thanks all for your time..
 
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