ADO.Net读取器获取数据库数据
string str = Configuration.ConfigurationManager.AppSettings[str].ToString();
string sql = "select * from company";
List<UserInfo> uf = new List<UserInfo>();
using (SqlConnection con = new SqlConnection(str))
{
using(SqlCommand cmd = new SqlCommand (sql,con))
{
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
UserInfo uInfo = new UserInfo();
uInfo.cName = dr[0].ToString();//姓名//..
uf.Add(uInfo);
}
}
}
return uf;