This is the webmethod with ajax and jquery. when the EmpID is like 123,12,123456 it open the popup box and show the output as i want but when EmpID is like A001,ABC it show the error like "Error while retrieving data of :" how to solve... Thanks in Advance
Query Data:-
$(document).on("click", ".editButton", function () { $("#myModal").focus(); var id = $(this).attr("data-id"); console.log(id); $("#btnUpdate").attr("edit-id", id); //alert(id); $.ajax({ type: "Post", contentType: "application/json; charset=utf-8", url: "Default3.aspx/EditData", data: '{eid: ' + id + '}', dataType: "json", success: function (data) { var empDetails = $.parseJSON(data.d); $.each(empDetails, function (index, value) { $("#FirstName1").val(value.EmpID); $("#MiddleName1").val(value.EmpName); $("#Surname1").val(value.EmpAddress); //alert("hi"); }); }, error: function () { alert("Error while retrieving data of :" + id); } }); }); });Html Table:-
<div class="row"> <div class="col-lg-12"> <br /> <br /> <div class="col-lg-12"> <div class="panel panel-default"> <div class="panel-heading"> Admin Employee Details Tables div> <div class="panel-body"> <div class="dataTable_wrapper"> <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer"> <div class="row"> <div class="col-sm-6"> <div class="dataTables_length" id="dataTables-example_length"> Show <select name="dataTables-example_length" aria-controls="dataTables-example" class="form-control input-sm" id="select"> <option value="5">5option> <option value="10">10option> <option value="25">25option> <option value="50">50option> <option value="100">100option> select> entrieslabel> div> div> <div class="col-sm-6"> <div id="dataTables-example_filter" class="dataTables_filter"> Search:<input type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" id="searchtxt" />label> div> div> div> <div class="row"> <div class="table-responsive"> <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer " role="grid" aria-describedby="dataTables-example_info"> <tr role="row"> <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 175px;" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">Emp IDth> <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 203px;" aria-label="Browser: activate to sort column ascending">Emp Nameth> <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 184px;" aria-label="Platform(s): activate to sort column ascending">Emp Addressth> tr> thead> <% for (var data = 0; data < TableData.Rows.Count; data++) { %> <tr class="gradeA odd " role="row"> <td class="sorting_1"> <%=TableData.Rows[data]["EmpID"]%> td> <%=TableData.Rows[data]["EmpName"]%> td> <%=TableData.Rows[data]["EmpAddress"]%> td> <input type="button" class="btn btn-primary editButton" data-id="<%=TableData.Rows[data]["EmpID"] %>" data-toggle="modal" data-target="#myModal" name="submitButton" id="btnEdit" value="Edit" /> td> <input type="button" class="btn btn-primary deleteButton" data-id="<%=TableData.Rows[data]["EmpId"] %>" name="submitButton" id="btnDelete" value="Delete" /> td> tr> <% } %> tbody> table> div> div> div> div> div> div> div> div> div>
C# Code-
[WebMethod]
public static string EditData(string eid)
{
string jsondata;
using(var con=new SqlConnection(ConnectString))
{ var query = "Select * from NewEmp where EmpID='" + eid + "' ";
using(var cmd=new SqlCommand(query, con)) {
using(var sda=new SqlDataAdapter()) {
cmd.Connection = con;
sda.SelectCommand = cmd; TableData.Clear();
sda.Fill(TableData);
jsondata = JsonConvert.SerializeObject(TableData); } } }
return jsondata; }
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vinay SinghPosted Aug 22, 2016, 4:26 AM
Vinay SinghPosted Aug 22, 2016, 4:24 AM
Bikesh SrivastavaPosted Aug 22, 2016, 1:44 AM
Ravi PatelPosted Aug 22, 2016, 1:13 AM
Ajay MalikPosted Aug 22, 2016, 12:24 AM
FirstName may not map to EmpID well. Middlename to EmpName, etc.
But overall, it sounds like something is expecting an integer input and you're giving it letters. Look for that and either change the input expectation to varchar/string or change the input to only consist of numbers.