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();
- }
- //for getdatalist
- 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 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??
Ramachandran MPosted Jan 29, 2020, 11:05 AM
var dataValue = { "studid": studid ,"studname": $("#txtname").val(), "studaddress": $("#txtaddress").val() };
$.ajax({
url: 'WebForm1.aspx/Edit',
type: 'POST',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
data: dataValue ,
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');
},
});
Jignesh KumarPosted Jan 28, 2020, 7:20 PM
rahul patilPosted Jan 28, 2020, 7:16 PM
Jignesh KumarPosted Jan 28, 2020, 6:03 PM
rahul patilPosted Jan 28, 2020, 5:51 PM
Ramachandran MPosted Jan 28, 2020, 5:25 PM