TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
rahul patil
NA
6
559
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
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
//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 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??
Reply
Answers (
6
)
How to create advert in MVC asp.net?
how to create swagger ui with versioning using.net core 3.1