Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. CREATE PROCEDURE UserLogin
  2. -- Add the parameters for the stored procedure here
  3. @Username varchar(50),
  4. @Password varchar(50)
  5.  
  6. SET NOCOUNT ON;
  7.  
  8. -- Insert statements for procedure here
  9. SELECT COUNT(*) from UserInfo where UserName=@Username AND
  10. Password=@Password
  11. END
  12. GO
  13.  
  14. namespace ADOLogin.Models
  15. {
  16. public class login
  17. {
  18. // public int UserId { get; set; }
  19. public string UserName { get; set; }
  20. public string Password { get; set; }
  21. }
  22. }
  23.  
  24. public class datacontext
  25. {
  26. public object Login(string username,string password)
  27. {
  28. SqlConnection con = new SqlConnection(@"Data
  29. Source=MydbSQLEXPRESS1;Initial Catalog=Practice;Integrated
  30. Security=True;MultipleActiveResultSets=True;Application
  31. Name=EntityFramework");
  32. SqlCommand cmd = new SqlCommand("UserLogin",con);
  33. cmd.CommandType = System.Data.CommandType.StoredProcedure;
  34.  
  35. cmd.Parameters.AddWithValue("@Username", username);
  36. cmd.Parameters.AddWithValue("@Password", password);
  37.  
  38. con.Open();
  39.  
  40. int usercount = (Int32)cmd.ExecuteScalar();
  41. return usercount;
  42.  
  43.  
  44. }
  45. }
  46.  
  47. public ActionResult Index(login obj)
  48. {
  49. datacontext db = new datacontext();
  50. db.Login(obj.UserName,obj.Password);
  51.  
  52. return View();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement