c# - Ajax function executes but data is not inserting to database -


when insert details in form , click on insert button, shows "user has been added successfully." data not inserted table. try check error in browser pressing f12, shows object con null. how solve this? in advance

c# web method:

[webmethod] public static void insertdata(consigneemast consignee) {     using(var scon = new sqlconnection(strconnection))     {         using(var cmd = new sqlcommand())         {                 cmd.commandtext = "addinconsigneetable";                 cmd.commandtype = commandtype.storedprocedure;                 cmd.connection = scon;                  cmd.parameters.addwithvalue("@code",consignee.code);                 cmd.parameters.addwithvalue("@name",consignee.name);                 cmd.parameters.addwithvalue("@address1",consignee.address1);                 cmd.parameters.addwithvalue("@address2",consignee.address2);                 cmd.parameters.addwithvalue("@address3",consignee.address3);                 cmd.parameters.addwithvalue("@city",consignee.city);                 cmd.parameters.addwithvalue("@pincode",consignee.pincode);                 cmd.parameters.addwithvalue("@country",consignee.country);                 cmd.parameters.addwithvalue("@telno1",consignee.telno1);                 cmd.parameters.addwithvalue("@telno2",consignee.telno2);                 cmd.parameters.addwithvalue("@telno3",consignee.telno3);                 cmd.parameters.addwithvalue("@emailid",consignee.emailid);                 cmd.parameters.addwithvalue("@contactperson",consignee.contactperson);                 cmd.parameters.addwithvalue("@remark",consignee.remark);             }     } } 

ajax, jquery code:

$(document).ready(function () {     $("#btninsertinconsignee").click(function () {         var con = {};         debugger;         con.name = $("#consigneename").val();         con.address1 = $("#regofficeaddress1").val();         con.address2 = $("#regofficeaddress2").val();         con.address3 = $("#regofficeaddress3").val();         con.city = $("#city").val();         con.country = $("#countryaddress").val();         con.pincode = $("#pincode").val();         con.telno1 = $("#telephoneno").val();         con.telno2 = $("#faxno").val();         con.telno3 = $("#mobileno").val();         con.contactperson = $("#contactperson").val();         con.emailid = $("#email").val();         con.remark = $("#remark").val();          $.ajax({                     type: "post",                     url: "consigneewithboot.aspx/insertdata",                     data: '{consignee: ' + json.stringify(con) + '}',                     datatype: "json",                     contenttype: "application/json; charset=utf-8",                     success: function () {                         debugger;                         alert("user has been added successfully.");                         debugger;                          //window.location.reload();                        },                     error: function () {                         debugger;                         alert("error while inserting data");                     }                 });                 return false;              });          }); 

sql server stored procedure:

alter procedure [dbo].[addinconsigneetable]     @code nvarchar(6) = '',     @name nvarchar(75),     @address1 nvarchar(75),     @address2 nvarchar(75),     @address3 nvarchar(75),     @city nvarchar(15),     @pincode nvarchar(10),     @country nvarchar(40),     @telno1 nvarchar(50),     @telno2 nvarchar(50),     @telno3 nvarchar(50),     @emailid nvarchar(250),     @contactperson nvarchar(75),     @remark nvarchar(max) begin     declare @totalcount int     declare @count nvarchar(10)      select @totalcount = (select count(code) consigneemast)      if @totalcount null        set @count = 'a' + convert(nvarchar(10), 1001)     else        set @count = 'a' + convert(nvarchar(10), 1001 + (@totalcount))      insert consigneemast ([code], [name], [address1], [address2],[address3], [city], [country], [pincode], [telno1], [telno2], [telno3],[contactperson], [emailid], [remark])     values (upper(@count), upper(@name), upper(@address1), upper(@address2), upper(@address3), upper(@city), upper(@country), upper(@pincode), upper(@telno1), upper(@telno2), upper(@telno3), upper(@contactperson), upper(@emailid), upper(@remark)) end 

inserdata function dosen't call executenonquery persist data in database command.

public static void insertdata(consigneemast consignee)     {         using(var scon=new sqlconnection(strconnection))         {             using(var cmd=new sqlcommand())             {                 scon.open();                 cmd.commandtext = "addinconsigneetable";                 cmd.commandtype = commandtype.storedprocedure;                 cmd.connection = scon;                  cmd.parameters.addwithvalue("@code",consignee.code);                 cmd.parameters.addwithvalue("@name",consignee.name);                 cmd.parameters.addwithvalue("@address1",consignee.address1);                 cmd.parameters.addwithvalue("@address2",consignee.address2);                 cmd.parameters.addwithvalue("@address3",consignee.address3);                 cmd.parameters.addwithvalue("@city",consignee.city);                 cmd.parameters.addwithvalue("@pincode",consignee.pincode);                 cmd.parameters.addwithvalue("@country",consignee.country);                 cmd.parameters.addwithvalue("@telno1",consignee.telno1);                 cmd.parameters.addwithvalue("@telno2",consignee.telno2);                 cmd.parameters.addwithvalue("@telno3",consignee.telno3);                 cmd.parameters.addwithvalue("@emailid",consignee.emailid);                 cmd.parameters.addwithvalue("@contactperson",consignee.contactperson);                 cmd.parameters.addwithvalue("@remark",consignee.remark);                 cmd.executenonquery();              }         }     } 

Comments