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.
- USE [JQueryDB]
- GO
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE TABLE [dbo].[Country](
- [CountryID] [int] IDENTITY(1,1) NOT NULL,
- [CountryName] nvarchar NULL,
- CONSTRAINT [PK_Country] PRIMARY KEY CLUSTERED
- (
- [CountryID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE procedure [dbo].[spGetCountryName]
- @term varchar(50)
- as
- begin
- select CountryName
- from Country
- where CountryName like @term +‘%’
- end
- GO
Step-2
Add database connection in a webconfig file of your project change data source and database as you created.
-
- <add name=“DBCS” connectionString=“data source=DESKTOP-K5N6EMF\SQLEXPRESS; database=JQueryDB;integrated security=SSPI” providerName=“System.Data.SqlClient;”/>
-
Step-3
Add CountryService.asmx right click on project add new item and choose .asmx file. Write below code.
#database #jquery #asp.net