Introduction

In this blog, we will discuss how to create autocomplete textbox in asp.net with the database using jQuery AJAX and web service.

Step-1

Create a database in SQL server of your choice as given below.

  1. USE [JQueryDB]  
  2. GO  
  3. SET ANSI_NULLS ON  
  4. GO  
  5. SET QUOTED_IDENTIFIER ON  
  6. GO  
  7. CREATE TABLE [dbo].[Country](  
  8.     [CountryID] [int] IDENTITY(1,1) NOT NULL,  
  9.     [CountryName] nvarchar NULL,  
  10.  CONSTRAINT [PK_Country] PRIMARY KEY CLUSTERED   
  11. (  
  12.     [CountryID] ASC  
  13. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]  
  14. ) ON [PRIMARY]  
  15.   
  16. GO  
  17. SET ANSI_NULLS ON  
  18. GO  
  19. SET QUOTED_IDENTIFIER ON  
  20. GO  
  21. CREATE procedure [dbo].[spGetCountryName]  
  22. @term varchar(50)  
  23. as  
  24. begin  
  25.     select CountryName  
  26.     from Country  
  27.     where CountryName like @term +‘%’  
  28. end  
  29. GO  

Step-2

Add database connection in a webconfig file of your project change data source and database as you created.

  1.   
  2.   <add name=“DBCS” connectionString=“data source=DESKTOP-K5N6EMF\SQLEXPRESS; database=JQueryDB;integrated security=SSPI” providerName=“System.Data.SqlClient;”/>  
  3.   

Step-3

Add CountryService.asmx right click on project add new item and choose .asmx file. Write below code.

#database #jquery #asp.net

Autocomplete Textbox Using jQuery AJAX With Database In ASP.NET
3.65 GEEK