in Education by
When I insert the details in form and click on insert button, it shows "User has been added successfully." But the data is not inserted into the table. I also try to check the error in browser by pressing F12, it shows the object con is null. How to solve this? Thanks 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) as begin declare @Totalcount int declare @Count nvarchar(10) select @Totalcount = (select COUNT(Code) from ConsigneeMast) if @Totalcount is null set @Count = 'A' + CONVERT(nvarchar(10), 1001) else set @Count = 'A' + CONVERT(nvarchar(10), 1001 + (@Totalcount)) insert into 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 JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
InserData function dosen't call any ExecuteNonQuery which will 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(); } } }

Related questions

0 votes
    When I insert the details in form and click on insert button, it shows "User has been added successfully ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    When I insert the details in form and click on insert button, it shows "User has been added successfully ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    DROP TYPE Position; CREATE OR REPLACE TYPE Position AS OBJECT (longitude NUMBER(11,7), lattitude NUMBER(11, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    How inserting data through stored procedure do reduces network traffic and increase database performance? (a) ... Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    I have a POST request that passes data to my database when the form is submitted. Photo of what I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I have a POST request that passes data to my database when the form is submitted. Photo of what I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    I have following code and I want to get data from service. I have set everything from what I get ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I have following code and I want to get data from service. I have set everything from what I get ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 12, 2022 in Education by JackTerrance
0 votes
    There is no summary available of the big O notation for operations on the most common data structures ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    There is no summary available of the big O notation for operations on the most common data structures ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I am trying to input text into the text box in 'www.google.com' and though it says the text ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    Registering members and allowing them to login (updating tables etc) all worked fine up until I made this change recently. ... , make the UserLevel 'Member'? Code for signing up:...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    My question is a variant of the question here However, there are two differences: I don't know how ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    My question is a variant of the question here However, there are two differences: I don't know how ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    First I'll explain my senario: I have a page in which users login or register. The login control ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 10, 2022 in Education by JackTerrance
...