/// <summary> /// 更新一条数据 /// </summary> public bool Update(UserFB.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Category set "); strSql.Append("category=@category,"); strSql.Append("time=@time"); strSql.Append(" where categoryID=@categoryID"); SqlParameter[] parameters = { new SqlParameter("@category", SqlDbType.VarChar, 64), new SqlParameter("@time", SqlDbType.SmallDateTime), new SqlParameter("@categoryID", SqlDbType.Int, 4) }; parameters[0].Value = model.category; parameters[1].Value = model.time; parameters[2].Value = model.categoryID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(UserFB.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Category("); strSql.Append("category,time)"); strSql.Append(" values ("); strSql.Append("@category,@time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@category", SqlDbType.VarChar, 64), new SqlParameter("@time", SqlDbType.SmallDateTime) }; parameters[0].Value = model.category; parameters[1].Value = model.time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(false); } else { return(true); } }
/// <summary> /// 得到一个对象实体 /// </summary> public UserFB.Model.Category DataRowToModel(DataRow row) { UserFB.Model.Category model = new UserFB.Model.Category(); if (row != null) { if (row["categoryID"] != null && row["categoryID"].ToString() != "") { model.categoryID = int.Parse(row["categoryID"].ToString()); } if (row["category"] != null) { model.category = row["category"].ToString(); } if (row["time"] != null && row["time"].ToString() != "") { model.time = DateTime.Parse(row["time"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public UserFB.Model.Category GetModel(int categoryID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 categoryID,category,time from Category "); strSql.Append(" where categoryID=@categoryID"); SqlParameter[] parameters = { new SqlParameter("@categoryID", SqlDbType.Int, 4) }; parameters[0].Value = categoryID; UserFB.Model.Category model = new UserFB.Model.Category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }