rahul patil

rahul patil

  • NA
  • 6
  • 509

How to edit a record using Jquery Ajax??

Jan 28 2020 3:22 PM
I want to edit a record but the record was not updated.
 
sp:
 
updatestud
 
ALTER PROCEDURE [dbo].[updatestud]
@studid int,
@studname varchar(50),
@studaddress varchar(50)
AS
BEGIN
update tblstud set studname=@studname,studaddress=@studaddress where studid=@studid;
END
 
 
 Webform1.aspx.cs
 
  1.         public static void EditData(int studid, string studname, string studaddress)  
  2.         {  
  3.             cn.Open();  
  4.   
  5.             
  6.             SqlCommand cmd = new SqlCommand("updatestud", cn);  
  7.             cmd.CommandType = CommandType.StoredProcedure;  
  8.             cmd.Parameters.AddWithValue("@studid", studid);  
  9.             cmd.Parameters.AddWithValue("@studname", studname);  
  10.             cmd.Parameters.AddWithValue("@studaddress", studaddress);  
  11.   
  12.             int i = cmd.ExecuteNonQuery();  
  13.   
  14.             if (i > 0)  
  15.             {  
  16.                 Console.WriteLine("Update Successfully");  
  17.             }  
  18.             else  
  19.             {  
  20.                 Console.WriteLine("Not Update Successfully");  
  21.             }  
  22.   
  23.             cn.Close();  
  24.             
  25.         }  
  26.   
Webform1.aspx
 
  1.                     //for getdatalist  
  2.                     function GetData() {  
  3.                         $.ajax({  
  4.   
  5.                             url: 'WebForm1.aspx/GetData',  
  6.                             type: 'post',  
  7.                             contentType: 'application/json;charset=utf-8',  
  8.                             datatype: 'json',  
  9.                             data: "{}",  
  10.                             success: function (data) {  
  11.                                 data = JSON.parse(data.d);  
  12.                                 for (var i = 0; i < data.length; i++) {  
  13.                                     $("#tbl").append('' + data[i].studname + '  ' + data[i].studaddress +  + data[i].studid + ', \'' + data[i].studname + '\' ,\'' + data[i].studaddress + '\')" /> ')  
  14.                                 }  
  15.                             },  
  16.                             error: function () {  
  17.                                 alert('Not Get Data')  
  18.                             },  
  19.                         });  
  20.                     }  

  21.                     //when I click on edit button then record going to form and then some changes in record and then press update then give an error   Uncaught ReferenceError: studid is not defined?
  22.                     function Update(studid, studname, studaddress) {  
  23.   
  24.                         $.ajax({  
  25.   
  26.                             url: 'WebForm1.aspx/EditData',  
  27.                             type: 'post',  
  28.                             contentType: 'application/json;charset=utf-8',  
  29.                             datatype: 'json',  
  30.                             data: "{studid: '" + studid + "',studname:'" + $("#txtname").val() + "',studaddress:'" + $("#txtaddress").val() + "'}",  
  31.                             success: function (data) {  
  32.   
  33.                                 data = JSON.parse(data.d);  
  34.   
  35.                                 studid = studid;  
  36.   
  37.                                 $("#txtname").val(studname);  
  38.                                 $("#txtaddress").val(studaddress);  
  39.   
  40.                                 if (studid != null) {  
  41.   
  42.                                     $("#btnupdate").val("Update");  
  43.   
  44.                                 }  
  45.                                   
  46.                                 studid = studid;  
  47.                             },  
  48.                             error: function () {  
  49.                                 alert('Update Error');  
  50.                             },  
  51.   
  52.                         });  
  53.                     }  
//when I click on edit button then record going to form and then some changes in record and then press update then give an error Uncaught ReferenceError: studid is not defined?
 
when i press on update then record going to form but again click on update then give an error
 
Response {"d":null}
 
WebForm1.aspx:84 Uncaught ReferenceError: studid is not defined
 
how to solve this issue?? 
 

Answers (6)