/// <summary> /// 得到一个对象实体 /// </summary> public Gymnasium_APP.Model.PositionInfoModel DataRowToModel(DataRow row) { Gymnasium_APP.Model.PositionInfoModel model=new Gymnasium_APP.Model.PositionInfoModel(); if (row != null) { if(row["ID"]!=null && row["ID"].ToString()!="") { model.ID=int.Parse(row["ID"].ToString()); } if(row["Name"]!=null) { model.Name=row["Name"].ToString(); } if(row["Price"]!=null) { model.Price=row["Price"].ToString(); } if(row["Des"]!=null) { model.Des=row["Des"].ToString(); } if(row["TypeName"]!=null) { model.TypeName=row["TypeName"].ToString(); } if(row["PState"]!=null) { model.PState=row["PState"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Gymnasium_APP.Model.PositionInfoModel GetModel(int ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 ID,Name,Price,Des,TypeName,PState from PositionInfo "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = ID; Gymnasium_APP.Model.PositionInfoModel model=new Gymnasium_APP.Model.PositionInfoModel(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }