public List<Ages> allAges()
{
string sql = "select * from T_Ages";
List<Ages> list = new List<Ages>();
Console.WriteLine(list.Count);
using (SqlDataReader row = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null))
{
while (row.Read())
{
Ages age = new Ages();
age.Id = row.GetInt32(0);
age.Name = row.GetString(1);
list.Add(age);
}
}
return list;
}
那你就试着写成这样age.Id=row.GetInt32("Id");age.Name=row.GetString("Name");
你的dataReader好像还没有关闭???
你的LIst没有长度,你就用索引 0.1,这是不对的,应用字段名。