/// <summary> /// 更新一条数据 /// </summary> public bool Update(bbs.Model.Section model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_section set "); strSql.Append("name=@name,"); strSql.Append("logo=@logo"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 40), new SqlParameter("@logo", SqlDbType.VarChar, 100), new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@t_z_id", SqlDbType.Int, 4), new SqlParameter("@t_u_id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.logo; parameters[2].Value = model.id; parameters[3].Value = model.t_z_id; parameters[4].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.Section DataRowToModel(DataRow row) { bbs.Model.Section model = new bbs.Model.Section(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["t_z_id"] != null && row["t_z_id"].ToString() != "") { model.t_z_id = int.Parse(row["t_z_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["name"] != null) { model.name = row["name"].ToString(); } if (row["logo"] != null) { model.logo = row["logo"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(bbs.Model.Section model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_section("); strSql.Append("t_z_id,t_u_id,name,logo)"); strSql.Append(" values ("); strSql.Append("@t_z_id,@t_u_id,@name,@logo)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@t_z_id", SqlDbType.Int, 4), new SqlParameter("@t_u_id", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.VarChar, 40), new SqlParameter("@logo", SqlDbType.VarChar, 100) }; parameters[0].Value = model.t_z_id; parameters[1].Value = model.t_u_id; parameters[2].Value = model.name; parameters[3].Value = model.logo; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public bbs.Model.Section GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,t_z_id,t_u_id,name,logo from t_section "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; bbs.Model.Section model = new bbs.Model.Section(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }