/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Summy DataRowToModel(DataRow row) { Maticsoft.Model.Summy model=new Maticsoft.Model.Summy(); 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["Pic"]!=null) { model.Pic=row["Pic"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Summy GetModel(int Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Id,Name,Price,Pic from Summy "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; Maticsoft.Model.Summy model=new Maticsoft.Model.Summy(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }