Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to delete data from database using mvc3?
    text
    copied!<p>I am new to Json datatype. how to retrive it.. please look at the code below. </p> <p>This is my Javascript code:</p> <pre><code>function fnDeleteSelected() { var count_checked = $("[name = 'myChkBox[]']:checked").length; var arrayOfID = []; $(':[name = "myChkBox[]"]:checked').each(function () { arrayOfID.push($(this).val()); }); var test = JSON.stringify(arrayOfID); alert(test); if (count_checked == 0) { alert("Please Select a Student to delete"); return false; } else { var confirmDel = confirm("Are you sure you want to delete this?"); if (confirmDel == true) { jQuery.ajax({ url: baseUrl + "DeleteSelected/", type: 'Post', dataType: 'Json', data: { Parameters: test }, success: function (msg) { jQuery("input:checkbox:checked").parents("tr").remove(); } });enter code here } } } </code></pre> <p>here data send to controller is parameters where parameters = ["143","144","145"]</p> <p>and my controller is: where Parameters is passed as "[\"143\",\"144\",\"145\"]"my question is how to parse the Parameters so that it can be embedded in sql statement</p> <pre><code>public JsonResult DeleteSelected(string [] Parameters) {string strConn = "Data Source=localhost;Initial Catalog=Information;Integrated Security=SSPI;"; SqlConnection conn = new SqlConnection(strConn); string strSql = "DELETE FROM dbStudent where ID in"; SqlCommand myCommand = new SqlCommand(strSql, conn); try { conn.Open(); myCommand.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return Json(Parameters, JsonRequestBehavior.AllowGet); } </code></pre> <p>what should be there in strSql..??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload