i want to make a textbox suggest all possible inputs based on a certain column in my database.

for example, i have a country column in the database and i want my textbox to display all countries from my database column that starts with P when i type it and so on. thanks :)

put a text box and button on a form

then use following code

Dim conn As New SqlConnection("Data Source=server;Initial Catalog=database;User ID=id; pwd=pass") 'basically connection string
        Dim cmd As New SqlCommand("SELECT columnname FROM table", conn)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "list") // list can be any name u want

        Dim col As New AutoCompleteStringCollection
        Dim i As Integer
        For i = 0 To ds.Tables(0).Rows.Count - 1
            col.Add(ds.Tables(0).Rows(i)("columnname").ToString())  //columnname same as in query


        TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
        TextBox1.AutoCompleteCustomSource = col
        TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
        TextBox1.AutoCompleteMode = AutoCompleteMode.Suggest
        TextBox1.AutoCompleteSource = AutoCompleteSource.CustomSource
        Dim DataCollection As New AutoCompleteStringCollection()
        TextBox1.AutoCompleteCustomSource = DataCollection

Full Source : Autocomplete textbox from database

This article has been dead for over six months. Start a new discussion instead.