.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Ajax >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Binding the sqlserver database fields into textbox i.e. Autocomplete complete extender...

Posted By:Ashfaque       Posted Date: May 10, 2011    Points: 40    Category: Ajax    URL: http://www.dotnetspark.com  

In my article i a have explained simplest way to achieve the task of search engine i.e. we can search the data of sql database,when the user prompted to retrieve the particular data from database just by entering the few characters they wish to retrieve the text box will automatically retrieve the related data starting with that letter entered by the users.its quite simple too.The main source i have enclosed here.
 

                           ***  My asp source code will look like this ****


   

   
   

   
                CompletionInterval="10" MinimumPrefixLength="1" ServiceMethod="Getinfo"
            ServicePath="Webservice.asmx" TargetControlID="TextBox1" UseContextKey="True">


   

   


The code snippet to call web method .here my web method is"GetInfo" and servicepath is "Webservice.asmx".The code is here...

[WebMethod]
        public string[] Getinfo(string prefixText)
{
 int count = 10;
 string sql = "Select * from PlanDetails Where Planname like @prefixText";
 SqlDataAdapter da = new SqlDataAdapter(sql,"Data Source=ADMIN-2BB4800E8;Initial Catalog=do;User ID=sa;Password=1a2s");
 da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText+ "%";
 DataTable dt = new DataTable();
 da.Fill(dt);
 string[] items = new string[dt.Rows.Count];
 int i = 0;
 foreach (DataRow dr in dt.Rows)
 {
     items.SetValue(dr["Planname"].ToString(), i);
   
    
  i++;
 }
 

 return items;
}
    }
Note:i retrieved the data from the database table called "Plandetails",the field which i retrieved and bind with the database is "Planname".

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend