//声明一个集合变量
List<Section> list = new List<Section>();
//SQL语句
string sql = string.Format("select Groups from Section");
//使用DataReader读取到数据库的信息
SqlDataReader reader = DBHelper.GetDataReader(sql);
while (reader.Read())
{
//实例化类
Section section = new Section();
//用类中的字段去接收读取到的信息并储存
section.Groups = reader["Groups"].ToString();
//往list中添加对象
list.Add(section);
}
reader.Close();
使用List集合获取数据库数据
最新推荐文章于 2024-01-25 22:33:14 发布