Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hai friends,
I am desiging a form with textbox.
If i type the textbox it should auto complete with value from the database.
Thank you,
regards,
Sissy ram
Posted
Comments
F. Xaver 26-Feb-14 4:22am    
Dim acList As New AutoCompleteStringCollection
acList.AddRange([Your values from database here])
TextBox1.AutoCompleteCustomSource = acList
TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
Sissy Ram 26-Feb-14 10:45am    
No that is not working friend
Sissy Ram 26-Feb-14 10:52am    
that code is not working friend,
say me a example,
Here i edited that line as like this but error shown

acList.AddRange("select TCODE from Tailor ")
F. Xaver 27-Feb-14 3:06am    
you can't run your SQL qry there..
AddRange want's a IEnumerable like String() or List(Of String) witch contains your Data.

You need to run that qry separately

1 solution

Oh thank you freind.
I solved this myself!
dim connection as oledbconnection="Connection path"
dim ds as dataset
dim da as oledbadapter
dim cmd as oledbcommand
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        fill_data()
    End Sub
Public Sub fill_data()
        con.open()
        cmd = New OleDbCommand("Select Columnname FROM tablename", connection)
        cmd.ExecuteNonQuery()
        Dim ds As New DataSet
        Dim da As New OleDbDataAdapter(cmd)
        da.Fill(ds, "Tablename")
        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        If ds.Tables("Tablemname").Rows.Count = 0 Then
        Else
            For i = 0 To ds.Tables("Tablename").Rows.Count - 1
                col.Add(ds.Tables("Tablename").Rows(i)("Columnname").ToString())
            Next
        End If
        TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
        TextBox1.AutoCompleteCustomSource = col
        TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
        con.close()
    End Sub
 
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