Database function skipping data
Hello, when I run the below method it is supposed to return a string array with a list of users, but when I run the debugger, the reader object has rows, but it skips over the while loop. Here is the code:
C#
public static List<string> RetrieveUserList()
{
List<string> users = new List<string>();
DBConnect.StartConnection(); // used to open connection with database
try
{
using (DBConnect.Conn) // Use open connection
{
string getUsers = "SELECT userName FROM client_schedule.user"; // create command string
using (MySqlCommand cmd = new MySqlCommand(getUsers, DBConnect.Conn))
{
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string temp = reader.GetString(0);
users.Add(temp);
}
}
}
}
catch (MySqlExeception ex)
{
DBConnect.StopConnection(); // close if exception occurs
MessageBox.Show(ex.Message);
}
DBConnect.StopConnection(); // close connection
return users;
}C#
public static List<string> RetrieveUserList()
{
List<string> users = new List<string>();
DBConnect.StartConnection(); // used to open connection with database
try
{
using (DBConnect.Conn) // Use open connection
{
string getUsers = "SELECT userName FROM client_schedule.user"; // create command string
using (MySqlCommand cmd = new MySqlCommand(getUsers, DBConnect.Conn))
{
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string temp = reader.GetString(0);
users.Add(temp);
}
}
}
}
catch (MySqlExeception ex)
{
DBConnect.StopConnection(); // close if exception occurs
MessageBox.Show(ex.Message);
}
DBConnect.StopConnection(); // close connection
return users;
}