Angular JS , asmx File and Sql Server Database

AngularJs Connection with Database....

AngularJs is client Side script . So For database Connectivity  , You will required  server side script like  ASP , PHP , JSP and so on.... 

Here We are using web services . web services work as middle ware between front end and back end.

.asmx File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Configuration;
using System.Data.Sql;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script;
namespace Angularjs
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
public WebService()
string conn = ConfigurationManager.ConnectionStrings["XXXXXX"].ConnectionString;
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void HelloWorld()
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.ContentType = "application/json";
HelloWorldData data = new HelloWorldData();
data.Message = ConvertDataTableTojSonString(GetDataTable());
public class HelloWorldData
public String Message;
public DataTable GetDataTable()
DataTable dataTable = new DataTable();
SqlConnection con= new SqlConnection (conn);
SqlCommand cmd = new SqlCommand("pro_select_all_active_user",con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
return dataSet.Tables[0];
public String ConvertDataTableTojSonString(DataTable dataTable)
{ System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List> tableRows = new List>();
Dictionary row;
foreach (DataRow dr in dataTable.Rows)
{ row = new Dictionary();
foreach (DataColumn col in dataTable.Columns)
row.Add(col.ColumnName, dr[col]);
return serializer.Serialize(tableRows);


<!DOCTYPE html>
<title>consume JSON web service</title>
<script src="">
<div ng-controller="questionsController">
search:<input type="text" ng-model="search" />
<tr ng-repeat="i in questions | filter:search">
<br /> </div>
var app = angular.module('serviceConsumer', []);
app.controller('questionsController', function ($scope, $http) {
var url = "WebService.asmx/Helloworld";
.success(function (data) {
var myjson = JSON.parse(data);
$scope.questions = JSON.parse(myjson);
.error(function (data) {
</body> </html>

Share on facebook Google Twitter

Web Engineers here !

Grideb is the group of engineers who provide excellent solution for domain scenario with experienced, talented and high skilled engineers. We work hard to reduce complication of user interface and improve better quality of service.

-- Chief Executive Officer, GRIDEB SERVICES

Contact Us

Office-1,FF ,One Square Office Mall
Uttar Pradesh 201004 (INDIA)
P: +91 (120) 260-6044
M: +91 90-1300-3421
Email ID

Grideb Services 2013-2014