Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more: , +
i am trying to auto complete text box control in C# which uses SQLServer 2005 ,I want to set AutoCompleteCustomSource to a collection which holds the retrieved values from database.I am little confusing about this ,say i am retrieving all values from a column of a table ,my question is particular column have 10000records , will it make my application to very slow?if it makes my application slow,how can i retrieve most recent values from that column, for a example last 20 records from that column.
Please can any one give a solution ?
Posted
Updated 24-May-11 8:42am
v3
Comments
Orcun Iyigun 24-May-11 15:13pm    
Well maybe you can add another column to your table indicating the recent value(s). When someone uses the corresponding record, you increment the value of the column on that record which you created for the recent value. Next time you sort the columns depending to this column getting the top 20 records. But I dont know how useful this is going to be.
Thabo@Codeproject 25-May-11 3:44am    
Thanks ....that is good idea!..Thanks again..
sairam.bhat 25-May-11 2:39am    
good qstn
Thabo@Codeproject 25-May-11 3:52am    
@sairam.bhat:Thanks

just updating reply from orc_orc_orc : add a identity column to your database table and then retrieve top 20 columns by firing a simple query somewhat like
"SELECT TOP 20 <column_name> FROM <table_name> ORDER BY <identity_column_name> "
 
Share this answer
 
Comments
sairam.bhat 25-May-11 2:40am    
good ans
Thabo@Codeproject 25-May-11 3:48am    
@ Ravi Gupta :Thanks i am accepting your and orc_orc_orc answer..Thanks again
Add this on form load
private AutoCompleteStringCollection AutoComplete1 = new AutoCompleteStringCollection();
private AutoCompleteStringCollection AutoComplete2 = new AutoCompleteStringCollection();

Create a function for Autocomplete.

C#
private void setAutoComplete()
        {
            DataTable dt = new DataTable();
            dt = GetData();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                scAutoComplete.Add(dt.Rows[i]["Auto"].ToString());
                scAutoComplete.Add(dt.Rows[i]["Code"].ToString());
            }
        }



GetData is a another function for Get Data from SQL Server and save in record in DataTable.
Happy coding :)
 
Share this answer
 
v2
Comments
sairam.bhat 25-May-11 2:39am    
good ans
divesh12 31-May-11 10:00am    
thanks sairam

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