/// <summary> /// 更新一条数据 /// </summary> public bool Update(bbs.Model.Reply model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_reply set "); strSql.Append("modifytime=@modifytime,"); strSql.Append("publishtime=@publishtime,"); strSql.Append("content=@content,"); strSql.Append("title=@title"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@modifytime", SqlDbType.DateTime), new SqlParameter("@publishtime", SqlDbType.DateTime), new SqlParameter("@content", SqlDbType.VarChar, 1000), new SqlParameter("@title", SqlDbType.VarChar, 50), new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@t_t_id", SqlDbType.Int, 4), new SqlParameter("@t_u_id", SqlDbType.Int, 4) }; parameters[0].Value = model.modifytime; parameters[1].Value = model.publishtime; parameters[2].Value = model.content; parameters[3].Value = model.title; parameters[4].Value = model.id; parameters[5].Value = model.t_t_id; parameters[6].Value = model.t_u_id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public bbs.Model.Reply DataRowToModel(DataRow row) { bbs.Model.Reply model = new bbs.Model.Reply(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["t_t_id"] != null && row["t_t_id"].ToString() != "") { model.t_t_id = int.Parse(row["t_t_id"].ToString()); } if (row["t_u_id"] != null && row["t_u_id"].ToString() != "") { model.t_u_id = int.Parse(row["t_u_id"].ToString()); } if (row["modifytime"] != null && row["modifytime"].ToString() != "") { model.modifytime = DateTime.Parse(row["modifytime"].ToString()); } if (row["publishtime"] != null && row["publishtime"].ToString() != "") { model.publishtime = DateTime.Parse(row["publishtime"].ToString()); } if (row["content"] != null) { model.content = row["content"].ToString(); } if (row["title"] != null) { model.title = row["title"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(bbs.Model.Reply model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_reply("); strSql.Append("t_t_id,t_u_id,modifytime,publishtime,content,title)"); strSql.Append(" values ("); strSql.Append("@t_t_id,@t_u_id,@modifytime,@publishtime,@content,@title)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@t_t_id", SqlDbType.Int, 4), new SqlParameter("@t_u_id", SqlDbType.Int, 4), new SqlParameter("@modifytime", SqlDbType.DateTime), new SqlParameter("@publishtime", SqlDbType.DateTime), new SqlParameter("@content", SqlDbType.VarChar, 1000), new SqlParameter("@title", SqlDbType.VarChar, 50) }; parameters[0].Value = model.t_t_id; parameters[1].Value = model.t_u_id; parameters[2].Value = model.modifytime; parameters[3].Value = model.publishtime; parameters[4].Value = model.content; parameters[5].Value = model.title; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public bbs.Model.Reply GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,t_t_id,t_u_id,modifytime,publishtime,content,title from t_reply "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; bbs.Model.Reply model = new bbs.Model.Reply(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }