public override User GetUser(ulong userID) { User result = User.Null; string statement = "SELECT * FROM Users WHERE UserID=@ID"; try { using (SqlConnection sqlConn = new SqlConnection(GetConnectionString())) { sqlConn.Open(); if (sqlConn.State == ConnectionState.Open) { SqlCommand sqlQuery = new SqlCommand(statement, sqlConn); sqlQuery.Parameters.AddWithValue("@ID", userID); SqlDataReader sqlDR = sqlQuery.ExecuteReader(); if (sqlDR.Read()) { User u = new User(); u.UserID = (ulong)sqlDR["UserID"]; u.Username = sqlDR["EmployeeType"].ToString(); u.Password = sqlDR["Password"].ToString(); return u; } result = User.Null; } } } catch { result = User.Null; } return result; }
public override List<User> GetAllUsers() { List<User> usr = new List<User>(); string statement = "SELECT * FROM Users"; try { using (SqlConnection sqlConn = new SqlConnection(GetConnectionString())) { sqlConn.Open(); if (sqlConn.State == ConnectionState.Open) { SqlCommand sqlQuery = new SqlCommand(statement, sqlConn); SqlDataReader sqlDR = sqlQuery.ExecuteReader(); while(sqlDR.Read()) { User u = new User(); u.UserID = Convert.ToUInt64(sqlDR["UserID"]); u.Username = sqlDR["EmployeeType"].ToString(); u.Password = sqlDR["Password"].ToString(); usr.Add(u); } return usr; } return null; } } catch { return null; } }