connection.Close();
connection.Open();
cmd = new MySqlCommand("select attend from credit_purchase where date='" + date + "'", connection);
dread = cmd.ExecuteReader();
while (dread.Read())
{
x = dread.GetValue(0).ToString();//this line to error
}
dread.close();
connection.close();