retrieve data from database using jquery autocomplete

Posted on 2013-01-18
Last Modified: 2013-01-22
Hello Experts,

I would like to have values from my database get autocompleted as I type in a TextBox control. I'm having trouble finding good examples of this online. Could really use some help.
Question by:asp_net2
  • 3
  • 2
LVL 20

Expert Comment

by:Russ Suter
ID: 38794621
If you're talking about a relatively small number of values then you should pull them into memory ahead of time. If you have a lot of records then you may be looking at a large number of queries in a short time which isn't an especially good idea.

Can you give me some idea of how many records you're looking at retrieving? There are ways to do this but the question is if it's a good idea or not.

Author Comment

ID: 38794650
I would say it would be around 150 - 300 records.
LVL 20

Expert Comment

by:Russ Suter
ID: 38794792
For a list that small I'd just query the database once at page load and store the values in memory.
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Author Comment

ID: 38794863
Ok, can you help with that. That part I already understand.
LVL 10

Accepted Solution

Monica P earned 500 total points
ID: 38799987

This is a good artice in found on net..Let u try and check

Author Comment

ID: 38801289

Thank you for the link. That worked out great. I have just a few small questions to ask though before closing this post.

1.) How can I use a Stored Procedure instead of an SQL Statement as below?

    public static List<string> GetAutoCompleteData(string username)
        List<string> result = new List<string>();

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CMDB"].ConnectionString))
            using (SqlCommand cmd = new SqlCommand("select DISTINCT product_name from ProductNumbers where product_name LIKE '%'+@SearchText+'%'", conn))
                cmd.Parameters.AddWithValue("@SearchText", username);

                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())

                return result;

Open in new window

2.) Is there a way to have another value get populated based on the selected value from the AutoComplete list? So for example. I have a textbox called Product Number that is getting retrieved using autocomplete. Once a user selects a value from autocomplete I then need to populate the value related to the selected autocomplete value to be returned to a label control. The values in the database are related I jsut don't know how to return the other value based on the selected value from the autocomplete.

I would be MORE than willing to create another ticket if you think you can assist me with that.

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 47
AWS CLI issues with Tags 3 32
Spacing between controls 4 17
Problem to page 4 29
Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now