Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace zdalnyszkolaWPF
  9. {
  10. class SQL
  11. {
  12.  
  13. public User GetUser(string login, string password)
  14. {
  15. User user = new User();
  16. using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnString))
  17. {
  18. try
  19. {
  20. string sql = string.Format(@"Select UserID,UserLogin,UserPassword from Users
  21. where UserID = {0} and UserPassword = '{1}'", login, password);
  22. SqlCommand command = new SqlCommand(sql, connection);
  23.  
  24. connection.Open();
  25.  
  26. SqlDataReader reader = command.ExecuteReader();
  27. if (reader.Read())
  28. {
  29.  
  30. user.UserID = Convert.ToInt32(reader["GID"]);
  31. user.UserLogin = reader["UserLogin"].ToString();
  32.  
  33. }
  34. reader.Close();
  35.  
  36. }
  37. catch (Exception e)
  38. {
  39. throw new Exception("GetUser " + e.Message);
  40. }
  41. finally
  42. {
  43. connection.Close();
  44. }
  45. return user;
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement