Advertisement
Guest User

web service code

a guest
Jul 31st, 2011
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Services;
  8. using System.Web.Services.Protocols;
  9. using System.Xml.Linq;
  10. using System.Data.SqlClient;
  11.  
  12. namespace LoginDetails
  13. {
  14. /// <summary>
  15. /// Summary description for Service1
  16. /// </summary>
  17. [WebService(Namespace = "http://tempuri.org/")]
  18. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  19. [ToolboxItem(false)]
  20. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  21. // [System.Web.Script.Services.ScriptService]
  22. public class Service1 : System.Web.Services.WebService
  23. {
  24.  
  25.  
  26. [WebMethod]
  27. public String GetLoginDetails(string UserName, string Password)
  28. {
  29.  
  30. try
  31. {
  32. using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=1234"))
  33. {
  34. myConnection.Open();
  35.  
  36. using (SqlCommand myCommand = new SqlCommand())
  37. {
  38. myCommand.Connection = myConnection;
  39. myCommand.CommandText = "SELECT COUNT(*) FROM Login WHERE UserName = @UserName AND Password = @Password";
  40. myCommand.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName;
  41. myCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password;
  42. return (int)myCommand.ExecuteScalar() == 1 ? "success" : "bad username or password";
  43. }
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. Console.WriteLine(ex.Message);
  49. return "an error occurred.";
  50. }
  51.  
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement