/// <summary> /// Convert IDataReader To ProductAttrInfo /// </summary> /// <param name="reader"></param> /// <returns></returns> public static ProductAttrInfo SetValue(IDataReader reader) { ProductAttrInfo info = new ProductAttrInfo(); int attrIDIndex = reader.GetOrdinal("AttrID"); int cateIDIndex = reader.GetOrdinal("CateID"); int attrNameIndex = reader.GetOrdinal("AttrName"); info.AttrID = reader.GetInt32(attrIDIndex); info.CateID = reader.GetInt32(cateIDIndex); info.AttrName = reader.GetString(attrNameIndex); return info; }
public bool Insert(ProductAttrInfo productAttrInfo) { StringBuilder sql=new StringBuilder(); sql.Append("INSERT INTO"); sql.Append(" [Tbl_ProductAttr]("); sql.Append("[CateID],"); sql.Append("[AttrName]"); sql.Append(") VALUES("); sql.Append("@CateID,"); sql.Append("@AttrName"); sql.Append(");SELECT @@IDENTITY;"); using(NetShopHelper dbhelper=new NetShopHelper()) { IDbDataParameter[] p_Parms=new IDbDataParameter[]{ dbhelper.CreateParameter("@CateID",productAttrInfo.CateID), dbhelper.CreateParameter("@AttrName",productAttrInfo.AttrName) }; int ret=(int)dbhelper.ExecuteScalar(sql.ToString(),p_Parms); productAttrInfo.AttrID=ret; return true; } }
public bool Update(ProductAttrInfo productAttrInfo) { StringBuilder sql = new StringBuilder(); sql.Append("UPDATE"); sql.Append(" [Tbl_ProductAttr]"); sql.Append(" SET"); sql.Append(" [CateID]=@CateID,"); sql.Append(" [AttrName]=@AttrName"); sql.Append(" WHERE"); sql.Append(" [AttrID]=@AttrID"); using(NetShopHelper dbhelper=new NetShopHelper()) { IDbDataParameter[] p_Parms = new IDbDataParameter[]{ dbhelper.CreateParameter("@AttrID",productAttrInfo.AttrID) }; return 0 < dbhelper.ExecuteNonQuery(sql.ToString(),p_Parms); } }