captainbulba
captainbulba
CC#
Created by captainbulba on 2/2/2023 in #help
❔ Best practice to retrieve MySQL columns
Hello wonderful people! Can you please help me understanding what would be the best practice to retrieve values of specific columns when I use MySQL query? Currently, I just hardcode names but this doesn't seem to be the ideal situation. I see that I can create an enum for the names and use Enum.Login.ToString() Or I can index it (like reader[0]) But both options has its flows as I can change the column name / change the order. What is the best practice to get specific columns? Or what method you personally use for a smaller scale application?
while (reader.Read())
{
User user = new User
{
Login = (string)reader["login"],
TeacherFlag = Convert.ToBoolean(reader["teacher_flag"]),
AdminFlag = Convert.ToBoolean(reader["admin_flag"])

};
Login.SetCurrentUser(user);
}
while (reader.Read())
{
User user = new User
{
Login = (string)reader["login"],
TeacherFlag = Convert.ToBoolean(reader["teacher_flag"]),
AdminFlag = Convert.ToBoolean(reader["admin_flag"])

};
Login.SetCurrentUser(user);
}
3 replies
CC#
Created by captainbulba on 1/30/2023 in #help
Storing login data
Hello everyone! I am trying to build a simple school management system in console. Once a user login I want to store some of the data in order to avoid querying for that data again. What would be the best approach? I thought of using static such as
public static class Login
{
public static string login { get; set; }
public static bool teacherFlag { get; set; }
public static bool adminFlag { get; set; }

}
public static class Login
{
public static string login { get; set; }
public static bool teacherFlag { get; set; }
public static bool adminFlag { get; set; }

}
But from what I read this approach is not good as multiple applications can mix up the information.
9 replies