Asp.net 怎么实现将表中所有数据读出
想把数据库Commet所有的数据读出,现在通过写IList方法来实现,怎么写一个循环把所有数据实体类对象添加到IList对象中Commet的实体类为megs AccessHelper中提供ExecuteSQLDataReader方法(Cmd, parameter).
我是这样写的
public IList<Megs> GetAll()
{
IList<Megs> lis = new List<Megs>();
string aa="select * from [commet]";
try
{
OleDbDataReader sdr = AccessHelper.AccessHelper.ExecuteSQLDataReader(aa, null);
int i=0;
while(sdr.Read())
{
Megs a = new Megs();
a.ID = (int)sdr["id"];
a.Name = (string)sdr["name"];
a.Sex = (string)sdr["sex"];
a.Content = (string)sdr["content"];
a.Email = (string)sdr["email"];
a.Tel = (int)sdr["tel"];
lis.Add(a);
i++;
}
return lis;
}
catch { return null; }
}
但是程序执行直接返回return null。