Guest User

Untitled

a guest
Jan 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(function() {
  3. $("#empcode").change(checkEmpCode);
  4. });
  5.  
  6. function checkEmpCode() {
  7. $.ajax({
  8. type: "POST",
  9. url: "Service.asmx/CheckEmpCode",
  10. data: "{empcode: '" + $('#empcode').val() + "'}",
  11. contentType: "application/json; charset=utf-8",
  12. dataType: "json",
  13. success: function(response) {
  14. if (response.d != "0") {
  15. $("#failureimage").show();
  16. }
  17. else{
  18. $("#successimage").show();
  19. }
  20.  
  21. }
  22. });
  23. }
  24.  
  25. </script>
  26.  
  27. [WebMethod]
  28. public int CheckEmpCode(string empcode)
  29. {
  30. string connect = @"Server=SERVER;Database=Database;Trusted_Connection=True;";
  31. string query = "SELECT COUNT(*) FROM Employee WHERE empcode = @empcode";
  32. using(SqlConnection conn = new SqlConnection(connect))
  33. {
  34. using(SqlCommand cmd = new SqlCommand(query, conn))
  35. {
  36. cmd.Parameters.AddWithValue("empcode", empcode);
  37. conn.Open();
  38. return (int)cmd.ExecuteScalar();
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment