Introduction
In this blog, we will learn how to insert and retrieve data using jQuery Ajax in asp.net. We will create a web service and consume that web service in our project with the help of jQuery Ajax.
Step 1
Create a database in the SQL server of your choice.
- CREATE TABLE [dbo].[tblEmployees](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [Name] nvarchar NULL,
- [Gender] char NULL,
- [Phone] nvarchar NULL,
- [Email] nvarchar NULL,
- [Age] [int] NULL,
- [Salary] nvarchar NULL,
- CONSTRAINT [PK_tblEmployees] PRIMARY KEY CLUSTERED
- (
- [ID] 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
-
- CREATE procedure [dbo].[spAddNewEmployee]
- (
- @Name nvarchar(50),
- @Gender char(10),
- @Phone nvarchar(50),
- @Email nvarchar(50),
- @Age int,
- @Salary nvarchar(50)
- )
- as
- begin
- insert into tblEmployees(Name,Gender,Phone,Email,Age,Salary)
- values(@Name,@Gender,@Phone,@Email,@Age,@Salary)
- end
-
- CREATE procedure [dbo].[spGetEmployees]
- as
- begin
- select ID,Name,Gender,Phone,Email,Age, Salary from tblEmployees
- end
Step 2
Add code in the webconfig file:
-
- <add name=“DBCS” connectionString=“data source=FARHAN\SQLEXPRESS; database=JQueryDB; integrated security=SSPI;” providerName=“System.Data.SqlClient”/>
-
- <system.web>
-
-
- <add name=“HttpGet”/>
-
-
- </system.web>
Step 3
Create class – right click on new item, choose class, give the name employee.cs:
- public class Employee
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public string Gender { get; set;}
- public string Phone { get; set; }
- public string Email { get; set; }
- public int Age { get; set; }
- public string Salary { get; set; }
- }
#ajax #asp.net #retrieve data