public List<Users> GetAllUsers() { SqlCommand cmd; List<Users> tempUserList = new List<Users>(); try { Connect(); cmd = new SqlCommand("SELECT Uname FROM Users", conn); SqlDataReader sqlReader; sqlReader = cmd.ExecuteReader(); if (sqlReader.HasRows) { while (sqlReader.Read()) { Users tempUser = new Users(); tempUser.UserName = sqlReader.GetString(0); tempUserList.Add(tempUser); } } // Cleanup command and connection objects. cmd.Dispose(); conn.Dispose(); } catch (Exception ex) { // Add error handling here for debugging. // This error message should not be sent back to the caller. System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message); } return tempUserList; }
public List<Users> GetInfoAboutSpecificUser(int userID) { SqlCommand cmd; List<Users> tempUserInfo = new List<Users>(); try { Connect(); cmd = new SqlCommand("SELECT Uname, Pwd, userRole, UserID, PersonalInfo, LastName, FirstName, Email, Tele FROM Users WHERE UserID=@userID", conn); cmd.Parameters.AddWithValue("@userID", 25); cmd.Parameters["@userID"].Value = userID; SqlDataReader sqlReader; sqlReader = cmd.ExecuteReader(); if (sqlReader.HasRows) { while (sqlReader.Read()) { Users tempUser = new Users(); tempUser.UserName = sqlReader.GetString(0); tempUser.Password = sqlReader.GetString(1); tempUser.UserRole = sqlReader.GetString(2); tempUser.UserId = sqlReader.GetInt32(3); tempUser.PersonalInfo = sqlReader.GetString(4); tempUser.LastName = sqlReader.GetString(5); tempUser.FirstName = sqlReader.GetString(6); tempUser.Email = sqlReader.GetString(7); tempUser.Tele = sqlReader.GetString(8); tempUserInfo.Add(tempUser); } } // Cleanup command and connection objects. cmd.Dispose(); conn.Dispose(); } catch (Exception ex) { // Add error handling here for debugging. // This error message should not be sent back to the caller. System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message); } return tempUserInfo; }