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
- public static void EditData(int studid, string studname, string studaddress)
- {
- cn.Open();
-
-
- SqlCommand cmd = new SqlCommand("updatestud", cn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@studid", studid);
- cmd.Parameters.AddWithValue("@studname", studname);
- cmd.Parameters.AddWithValue("@studaddress", studaddress);
-
- int i = cmd.ExecuteNonQuery();
-
- if (i > 0)
- {
- Console.WriteLine("Update Successfully");
- }
- else
- {
- Console.WriteLine("Not Update Successfully");
- }
-
- cn.Close();
-
- }
-
Webform1.aspx
-
- function GetData() {
- $.ajax({
-
- url: 'WebForm1.aspx/GetData',
- type: 'post',
- contentType: 'application/json;charset=utf-8',
- datatype: 'json',
- data: "{}",
- success: function (data) {
- data = JSON.parse(data.d);
- for (var i = 0; i < data.length; i++) {
- $("#tbl").append('' + data[i].studname + ' ' + data[i].studaddress + ' + data[i].studid + ', \'' + data[i].studname + '\' ,\'' + data[i].studaddress + '\')" /> ')
- }
- },
- error: function () {
- alert('Not Get Data')
- },
- });
- }
- //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?
- function Update(studid, studname, studaddress) {
-
- $.ajax({
-
- url: 'WebForm1.aspx/EditData',
- type: 'post',
- contentType: 'application/json;charset=utf-8',
- datatype: 'json',
- data: "{studid: '" + studid + "',studname:'" + $("#txtname").val() + "',studaddress:'" + $("#txtaddress").val() + "'}",
- success: function (data) {
-
- data = JSON.parse(data.d);
-
- studid = studid;
-
- $("#txtname").val(studname);
- $("#txtaddress").val(studaddress);
-
- if (studid != null) {
-
- $("#btnupdate").val("Update");
-
- }
-
- studid = studid;
- },
- error: function () {
- alert('Update Error');
- },
-
- });
- }
//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??