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
Migold Live
NA
34
1.9k
Deleting records from two tables using INNER JOIN delete
Apr 6 2018 10:39 AM
please can you help me fix this multiple delete procedure query, nothing is been deleted on execution
when i click the delete button on modal to delete records from two tables, the jquery is executed but nothing is been deleted from the two tables. Here is the full code
<script type=
"text/javascript"
>
//delete 1
$(function () {
$(
'[id*=btndelet55]'
).on(
'click'
, function () {
var id = $(
this
).closest(
'tr'
).find($(
'[id*=ProdID]'
)).text();
$(
'[id*=delet-modalNOW]'
).modal(
'show'
);
$.ajax({
type:
"POST"
,
url:
"/HomePage.aspx/GetUSERPostDelet"
,
data:
'{id:"'
+ id +
'"}'
,
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
success: function (response) {
// clear old value
$(
".id"
).html(
''
);
$(
".imageuser8"
).attr(
'src'
,
''
);
$(
".username"
).html(
''
);
$(
".name"
).html(
''
);
$(
".senddate5"
).html(
''
);
$(
".contentpost"
).html(
''
);
$(
".sharecontent"
).html(
''
);
$(
".imagename15"
).html(
''
);
$(
".path"
).html(
''
);
// Assign new value
if
(response.d.length > 0) {
$(
".id"
).html(response.d[0].Id);
$(
".imageuser8"
).attr(
'src'
,
'/PROFILEPHOTOS/'
+ response.d[0].Imageuser7);
$(
".username"
).html(response.d[0].UserName);
$(
".name"
).html(response.d[0].Name);
$(
".senddate5"
).html(response.d[0].SendDate);
$(
".contentpost"
).html(response.d[0].ContentPost);
$(
".sharecontent"
).html(response.d[0].ShareContent);
$(
".imagename15"
).html(response.d[0].imagename15);
$(
".path"
).html(response.d[0].path);
}
},
});
return
false
;
});
$(
'[id*=buttondelete]'
).click(function () {
// var id = "1";
var id = $(
'.id'
).html().trim();
var name = $(
'.name'
).html().trim();
var username = $(
'.username'
).html().trim();
var contentPost = $(
'.contentpost'
).html().trim();
var sharecontent = $(
'.sharecontent'
).html().trim();
var senddate5 = $(
'.senddate5'
).html().trim();
var imagename15 = $(
'.imagename15'
).html().trim();
var path = $(
'.path'
).html().trim();
// If you ant to insert "PROFILEPHOTOS/Test.jpg" format then use the below line
var imageuser8 = $(
'.imageuser8'
).attr(
'src'
).slice(($(
'.imageuser8'
).attr(
'src'
).lastIndexOf(
'/'
) + 1), $(
'.imageuser8'
).attr(
'src'
).length);
//If you ant to insert "Test.jpg" format then use the below line
// var TXTcomments = $("#TXTcommentsSHARE").val();
var dataObj = {
id: id,
name: name,
username: username,
contentpost: contentPost,
sharecontent: sharecontent,
//TXTcomments: TXTcomments,
senddate5: senddate5,
imagename15: imagename15,
path: path,
imageuser8: imageuser8
};
$.ajax({
type:
"POST"
,
url:
"/HomePage.aspx/DeletUSERpostnow"
,
data: JSON.stringify(dataObj),
//data: "{id:'" + id + "',name:'" + name + "',username:'" + username + "',contentpost:'" + contentPost + "',TXTcomments:'" + TXTcomments + "',senddate5:'" + senddate5 + "',imagename15:'" + imagename15 + "',path:'" + path + "',imageuser8:'" + imageuser8 + "'}",
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
success: function (response) {
$(
'#delet-modalNOW'
).modal(
'hide'
);
$(
"#lblText"
).html(
'Post Deleted Successfully.'
);
$(
'#dialog1'
).fadeIn(
'slow'
).delay(1000).fadeOut(
'slow'
);
window.location.reload();
// clear value
$(
".id"
).html(
''
);
$(
".imageuser8"
).attr(
'src'
,
''
);
$(
".username"
).html(
''
);
$(
".name"
).html(
''
);
$(
".senddate5"
).html(
''
);
$(
".contentpost"
).html(
''
);
$(
".sharecontent"
).html(
''
);
$(
".imagename15"
).html(
''
);
$(
".path"
).html(
''
);
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
return
false
;
});
});
</script>
....................................
//delet post now
[WebMethod]
public
static
void
DeletUSERpostnow(
int
id,
string
username)
{
string
constr = ConfigurationManager.ConnectionStrings[
"DB"
].ConnectionString;
using
(SqlConnection con =
new
SqlConnection(constr))
{
//DELETE USERPost , SHAREPOSTS FROM USERPost INNER JOIN SHAREPOSTS
//WHERE USERPost.ID= SHAREPOSTS.ID and USERPost.UserName =@UserName
using
(SqlCommand cmd =
new
SqlCommand(
"GetDeletboth"
))
// ("DELETE USERPost, SHAREPOSTS FROM USERPost INNER JOIN SHAREPOSTS WHERE USERPost.ID= SHAREPOSTS.ShareId and USERPost.UserName =@UserName"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@UserName"
, HttpContext.Current.Session[
"userName"
].ToString());
cmd.Parameters.AddWithValue(
"@ID"
, id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
procedure
BEGIN
DELETE up2 FROM SHAREPOSTS up2 INNER JOIN USERPost up1 ON up1.Id = up2.ShareId WHERE up1.Id =@ID AND up1.UserName=@UserName
}
}
Reply
Answers (
1
)
Auto create image inside button from sql table and dimensio?
How To Get ID from Gridview when image Button Clicked.?