title: save data in sql server database using angularjs by asp.net
body: <p>i have this program n which i wan to save data in SQl data base using angularJS by ASP.net front end but i am not getting any response when i i am clicking on submit button </p>
  
  <p>I created a web service file 
  UserService.asmx</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Configuration;
  using System.Data;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Web;
  using System.Web.Script.Services;
  using System.Web.Services;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  public class UserService : System.Web.Services.WebService
  {
  string con;
  SqlConnection con1;
  public UserService()
  {
      con = ConfigurationManager.ConnectionStrings["tbt_db"].ConnectionString;
      con1 = new SqlConnection(con);
  }
  
  [WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public string saveUserDetails(String ID, String firstName)
  {
      SqlCommand cmd;
      try
      {
          con1.Open();
          cmd = con1.CreateCommand();
          cmd.CommandText = "INSERT INTO emp(ID,FirstName)VALUES(@ID,@FirstName)";
          cmd.Parameters.AddWithValue("@ID", ID);
          cmd.Parameters.AddWithValue("@FirstName", firstName);
          cmd.ExecuteNonQuery();
          return "Record Inserted Successfully";
      }
      catch (Exception)
      {
          throw;
      }
      finally
      {
          if (con1.State == ConnectionState.Open)
          {
              con1.Close();
          }
  
      }
  }
  
  public string HelloWorld()
  {
      return "Hello World";
  }
  
  }
  </code></pre>
  
  <p>My Script File is</p>
  
  <pre><code>$scope.save = function () {
  $http.Post({
      type: "POST",
      url: "UserService.asmx/saveUserDetails",
      data: "{'" + $scope.ID + "','" + $scope.firstName + "'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (msg) {
      alert(msg.d);
  },
  error: function (msg) {
      alert(msg.d);
  }
   });
   };
  </code></pre>
  
  <p>my aspx file is</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="memb.aspx.cs" Inherits="memb" %&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;script src="js/angular.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1" ng-controller="UserCntrl" ng-submit="save()"&gt;
  &lt;div&gt;
      &lt;p&gt;EMP ID: &lt;/p&gt;
      &lt;input id="Text1" type="text" placeholder="EMP ID" ng-model="ID" /&gt;
       &lt;p&gt;First Name: &lt;/p&gt;
      &lt;input id="Text2" type="email" placeholder="First Name" ng-model="firstName" /&gt;
      &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;input id="Button1" type="submit" value="submit" /&gt;
    &lt;/div&gt;
   &lt;div&gt;
      &lt;input type="button" id="btnFetch" value="Fetch" ng-click="getUser()"/&gt;
   &lt;/div&gt;
   &lt;div id="showdata"&gt;
   &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;firstName&lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;{{ID}}&lt;/td&gt;
          &lt;td&gt;{{firstName}}&lt;/td&gt;
  
      &lt;/tr&gt;
   &lt;/table&gt;            
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>no data is storing in database </p>