public IList<UserInfo> GetAll()
{
string strSql = "getAll";
SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.StoredProcedure, strSql, null);
UserInfo userInfo = null;
IList<UserInfo> userInfoList = new List<UserInfo>();
if (dr.Read())
{
userInfo = new UserInfo();
userInfo.UserId = (int)dr["UserID"];
userInfo.UserName = dr["UserName"].ToString();
userInfo.UserSex = dr["UserSex"].ToString();
userInfo.UserDesc = dr["UserDesc"].ToString();
userInfoList.Add(userInfo);
}
return userInfoList;
}
这是那个方法,只能得到一条数据!
很郁闷,为啥呢??
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(connectionString);
try
{
PrepareCommand(cmd, con, null, cmdType, cmdText, commandParameters);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return dr;
}
catch
{
con.Close();
throw;
}
}
这个是SqlHelper里面的方法,
我不知道为什么,请大家帮忙解决下!
谢谢!!
怎么老有不会的??