Link to home
Create AccountLog in
Avatar of Cannibal_Jack
Cannibal_Jack

asked on

Data from SQL database for textbox autocomplete

Hi, Is there anyway without having to download new components to make the autocomplete function of a textbox read from a sql database? I have managed to get a combobox to get information from a database but I can seem to manage this, any help or advice would be great, thanks.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

1) Set up the TextBox:

   AutoCompleteMode = Suggest
   AutoCompleteSource = CustomSource

2) Get a DataTable with unique names from the table.

3) Loop through the DataRow elements for the DataTable, and get the names, and add them to the AutoCompleteCustomSource collection.
Avatar of Cannibal_Jack
Cannibal_Jack

ASKER

Hi, I've done step one. I also know how to open a connection to my sql database. But how do I do steps 2 and 3? I would prefer to code it than use a wizard or such. an example would be great. thanks.
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks. How do I point the autocomplete to this dataset now?
Add all the values from the dataset to the AutoCompleteCustomSource

For Each dRow In myTable.Rows
   Textbox.AutoCompleteCustomSource.Add(drow("fieldname");
 Next

http://www.unwindsoftware.com/blog/2006_12_01_archive.html
Hi, I've entered everything now, but it's saying that dRow and ds.Rows are not declared, I'm new at this so how would I declare them? thanks for your help
Dim dRow as Datarow
(System.Data.DataRow)