Migold Live

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
  1.  <script type="text/javascript">  
  2.        //delete 1  
  3.        $(function () {  
  4.            $('[id*=btndelet55]').on('click', function () {  
  5.                var id = $(this).closest('tr').find($('[id*=ProdID]')).text();  
  6.                $('[id*=delet-modalNOW]').modal('show');  
  7.                $.ajax({  
  8.                    type: "POST",  
  9.                    url: "/HomePage.aspx/GetUSERPostDelet",  
  10.                    data: '{id:"' + id + '"}',  
  11.                    contentType: "application/json; charset=utf-8",  
  12.                    dataType: "json",  
  13.                    success: function (response) {  
  14.                        // clear old value  
  15.                        $(".id").html('');  
  16.                        $(".imageuser8").attr('src''');  
  17.                        $(".username").html('');  
  18.                        $(".name").html('');  
  19.                        $(".senddate5").html('');  
  20.                        $(".contentpost").html('');  
  21.                        $(".sharecontent").html('');  
  22.                          
  23.   
  24.                        $(".imagename15").html('');  
  25.                        $(".path").html('');  
  26.                        // Assign new value  
  27.   
  28.                        if (response.d.length > 0) {  
  29.                            $(".id").html(response.d[0].Id);  
  30.                            $(".imageuser8").attr('src''/PROFILEPHOTOS/' + response.d[0].Imageuser7);  
  31.                            $(".username").html(response.d[0].UserName);  
  32.                            $(".name").html(response.d[0].Name);  
  33.                            $(".senddate5").html(response.d[0].SendDate);  
  34.                            $(".contentpost").html(response.d[0].ContentPost);  
  35.                            $(".sharecontent").html(response.d[0].ShareContent);  
  36.                            $(".imagename15").html(response.d[0].imagename15);  
  37.                            $(".path").html(response.d[0].path);  
  38.                        }  
  39.                    },  
  40.   
  41.                });  
  42.                return false;  
  43.            });  
  44.            $('[id*=buttondelete]').click(function () {  
  45.                // var id = "1";  
  46.                var id = $('.id').html().trim();  
  47.                var name = $('.name').html().trim();  
  48.                var username = $('.username').html().trim();  
  49.                var contentPost = $('.contentpost').html().trim();  
  50.                var sharecontent = $('.sharecontent').html().trim();  
  51.                var senddate5 = $('.senddate5').html().trim();  
  52.                var imagename15 = $('.imagename15').html().trim();  
  53.                var path = $('.path').html().trim();  
  54.                // If you ant to insert "PROFILEPHOTOS/Test.jpg" format then use the below line  
  55.                var imageuser8 = $('.imageuser8').attr('src').slice(($('.imageuser8').attr('src').lastIndexOf('/') + 1), $('.imageuser8').attr('src').length);  
  56.   
  57.                //If you ant to insert "Test.jpg" format then use the below line  
  58.                // var TXTcomments = $("#TXTcommentsSHARE").val();  
  59.                var dataObj = {  
  60.                    id: id,  
  61.                    name: name,  
  62.                    username: username,  
  63.                    contentpost: contentPost,  
  64.                    sharecontent: sharecontent,  
  65.                    //TXTcomments: TXTcomments,  
  66.                    senddate5: senddate5,  
  67.                    imagename15: imagename15,  
  68.                    path: path,  
  69.                    imageuser8: imageuser8  
  70.                };  
  71.                $.ajax({  
  72.                    type: "POST",  
  73.                    url: "/HomePage.aspx/DeletUSERpostnow",  
  74.                    data: JSON.stringify(dataObj),  
  75.                    //data: "{id:'" + id + "',name:'" + name + "',username:'" + username + "',contentpost:'" + contentPost + "',TXTcomments:'" + TXTcomments + "',senddate5:'" + senddate5 + "',imagename15:'" + imagename15 + "',path:'" + path + "',imageuser8:'" + imageuser8 + "'}",  
  76.                    contentType: "application/json; charset=utf-8",  
  77.                    dataType: "json",  
  78.                    success: function (response) {  
  79.                        $('#delet-modalNOW').modal('hide');  
  80.                        $("#lblText").html('Post Deleted Successfully.');  
  81.                        $('#dialog1').fadeIn('slow').delay(1000).fadeOut('slow');  
  82.                        window.location.reload();  
  83.                        // clear value  
  84.                        $(".id").html('');  
  85.                        $(".imageuser8").attr('src''');  
  86.                        $(".username").html('');  
  87.                        $(".name").html('');  
  88.                        $(".senddate5").html('');  
  89.                        $(".contentpost").html('');  
  90.                        $(".sharecontent").html('');  
  91.                        $(".imagename15").html('');  
  92.                        $(".path").html('');  
  93.                    },  
  94.                    failure: function (response) {  
  95.                        alert(response.d);  
  96.                    },  
  97.                    error: function (response) {  
  98.                        alert(response.d);  
  99.                    }  
  100.                });  
  101.                return false;  
  102.            });  
  103.        });  
  104.     </script>  
  105.     ....................................  
  106.   
  107.   
  108. //delet post now  
  109.     [WebMethod]  
  110.     public static void DeletUSERpostnow(int id, string username)  
  111.     {  
  112.         string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;  
  113.         using (SqlConnection con = new SqlConnection(constr))  
  114.         {  
  115.             //DELETE USERPost , SHAREPOSTS  FROM USERPost  INNER JOIN SHAREPOSTS    
  116.             //WHERE USERPost.ID= SHAREPOSTS.ID and USERPost.UserName =@UserName  
  117.             using (SqlCommand cmd = new SqlCommand("GetDeletboth"))  
  118.                   
  119.               //  ("DELETE USERPost, SHAREPOSTS  FROM USERPost  INNER JOIN SHAREPOSTS WHERE USERPost.ID= SHAREPOSTS.ShareId and USERPost.UserName =@UserName"))  
  120.             {  
  121.                 cmd.CommandType = CommandType.StoredProcedure;  
  122.                 cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"].ToString());  
  123.                 cmd.Parameters.AddWithValue("@ID", id);  
  124.                 cmd.Connection = con;  
  125.   
  126.                 con.Open();  
  127.                 cmd.ExecuteNonQuery();  
  128.                 con.Close();  
  129.                  
  130.                 }  
  131.   
  132.   
  133. procedure  
  134.   
  135. BEGIN  
  136.   
  137. DELETE  up2 FROM SHAREPOSTS up2 INNER JOIN USERPost up1 ON up1.Id = up2.ShareId WHERE up1.Id =@ID AND up1.UserName=@UserName   
  138.   
  139.             }  
  140.           
  141.     }  
 

Answers (1)