I have a class like below,
class Student
{
public string Name {get; set;}
public string Surname {get; set;}
public int Age {get; set;}
public string Address {get; set;}
}
And I have a MySql table with 50,000 records. The Structure of the table is like below,
ID NAME SURNAME AGE ADDRESS
1 Joe Philip 20 Moscow
2 Misha Johny 25 London
...
And I have a C# code,
List<Student> students = new List<Student>();
string sql = "SELECT name,surname,age,address FROM Students";
command.CommandText = sql;
MySqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
Student st = new Student();
st.Name = reader["Name"].ToString();
st.Surname = reader["Surname"].ToString();
st.Age = Convert.ToInt32(reader["Age"].ToString());
st.Address = reader["Address"].ToString();
students.Add(st);
}
But it works very slow. Which method do you advice to make this code run faster?
UPDATE:
When I use this code,
DataTable dt = new DataTable();
adapter.Fill(dt);
It works very well and speed is very normal. But what is the problem I try it with my own classes?
stringto anintproperty (age).