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;

posted @ 2016-10-10 14:29  李文平  阅读(385)  评论(0编辑  收藏  举报