Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(function() {
- $("#empcode").change(checkEmpCode);
- });
- function checkEmpCode() {
- $.ajax({
- type: "POST",
- url: "Service.asmx/CheckEmpCode",
- data: "{empcode: '" + $('#empcode').val() + "'}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function(response) {
- if (response.d != "0") {
- $("#failureimage").show();
- }
- else{
- $("#successimage").show();
- }
- }
- });
- }
- </script>
- [WebMethod]
- public int CheckEmpCode(string empcode)
- {
- string connect = @"Server=SERVER;Database=Database;Trusted_Connection=True;";
- string query = "SELECT COUNT(*) FROM Employee WHERE empcode = @empcode";
- using(SqlConnection conn = new SqlConnection(connect))
- {
- using(SqlCommand cmd = new SqlCommand(query, conn))
- {
- cmd.Parameters.AddWithValue("empcode", empcode);
- conn.Open();
- return (int)cmd.ExecuteScalar();
- }
- }
- }
Add Comment
Please, Sign In to add comment