/// <summary> /// 根据参数userId,获取购物篮详细信息 /// </summary> /// <param name="userId">用户ID</param> public void LoadData(int userId) { Database db = new Database(); //实例化一个Database类 string sql = ""; sql = "Select * from [Cart] where UserID = " + userId; SqlDataReader reader = db.GetDataReader(sql); //利用Database类的GetDataRow方法查询用户数据 //根据查询得到的数据,对成员安全赋值 while (reader.Read()) { if (this._cartId == 0) { this._cartId = GetSafeData.ValidateDataReader_N(reader, "CartId"); this._userId = GetSafeData.ValidateDataReader_N(reader, "UserId"); } this._books.Add(GetSafeData.ValidateDataReader_N(reader, "BookId")); this._amount.Add(GetSafeData.ValidateDataReader_N(reader, "Amount")); this._exist = true; } if (this._cartId == 0) { this._exist = false; } }