End Google Ads 201810 - BS.net 01 --> Hi, i am using mysql connector for my C# project.

I want to retrieve all the values from the database where username = "testing"

Database.cs

public MySqlDataReader getAccountDetails(String username)
{
Connect();
command = conn.CreateCommand();
command.CommandText = "Select * from accounts where admin_num ='" + username + "'";
reader = command.ExecuteReader();
Close();
return reader;
}

frmMain.cs

private void frmMain_Load(object sender, EventArgs e)
{
toolStripDateLabel.Text = DateTime.Now.ToString();
db.Connect();
MySqlDataReader reader = db.getAccountDetails(username.ToString());

while (reader.Read())
{
string thisrow = "";
for (int i = 0; i < reader.FieldCount; i++)
thisrow += reader.GetValue(i).ToString() + ",";
listBox1.Items.Add(thisrow);
}
db.Close();
}

it gives me an error "Invalid attempt to Read when reader is closed."