In this article I provide a quick overview of how to insert a record into SQL Server using jQuery. You can do it many ways such as using Generic Handlers and using a WCF service. Here you will see it using Generic Handlers in ASP.Net. First we create a database table named "Test".
Creating SQL Database Table
This database contains one table named test.
CREATE TABLE [dbo].[Test](
[Name] [varchar](50) NULL,
[Email] [varchar](100) NULL
)
Now press F5 to execute the script above that looks like this:

ASP.NET Handler
Right-click your ASP.NET Project then select "Add New Item" -> "Generic Handler" and give it the name "Test.ashx".

The default handler (ashx) file code looks like this:
<%@ WebHandler Language="C#" Class="Test" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
Now create a .cs class file in the application and provide the same name as in:
Class="Test"
Now use "CTRL+X" and the following code from the code above.
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
Now paste it into the .cv file. The code in the file will look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class Test : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (HttpContext.Current.Request.QueryString["StrMethod"].ToUpper() == "SAVE")
{
Connection();
}
}
public bool IsReusable
{
get
{
return false;
}






Rohatash KumarPosted May 21, 2013, 11:13 PM
Thanks harjinder.
Harjinder SinghPosted May 18, 2013, 3:09 AM
Thanks! For this valuable source code. Really helped me a-lot.