from table it read only int value from EmpID but when it str

Aug 22 2016 12:14 AM
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"> <label> Show <select name="dataTables-example_length" aria-controls="dataTables-example" class="form-control input-sm" id="select"> 
<option value="5">5</option> <option value="10">10</option> 
<option value="25">25</option> <option value="50">50</option> 
<option value="100">100</option> </select>                                             
entries</label> </div> </div> <div class="col-sm-6"> <div id="dataTables-example_filter" class="dataTables_filter"> <label>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"> 
<thead> <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 ID</th> <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 Name</th> <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 Address</th> </tr> </thead> <tbody> <% for (var data = 0; data < TableData.Rows.Count; data++) { %> <tr class="gradeA odd " role="row"> <td class="sorting_1"> <%=TableData.Rows[data]["EmpID"]%> </td> <td> <%=TableData.Rows[data]["EmpName"]%> </td> <td> <%=TableData.Rows[data]["EmpAddress"]%> </td> <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> <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> <!-- /.table-responsive --> </div> <!-- /.panel-body --> </div> <!-- /.panel --> </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; }

Answers (5)