/// <summary> /// 增加一条数据 /// </summary> public int Add(Hoto.Model.sys_channel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_sys_channel("); strSql.Append("model_id,name,title,sort_id)"); strSql.Append(" values ("); strSql.Append("@model_id,@name,@title,@sort_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@model_id", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.NVarChar, 100), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.model_id; parameters[1].Value = model.name; parameters[2].Value = model.title; parameters[3].Value = model.sort_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hoto.Model.sys_channel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_sys_channel set "); strSql.Append("model_id=@model_id,"); strSql.Append("name=@name,"); strSql.Append("title=@title,"); strSql.Append("sort_id=@sort_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@model_id", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.NVarChar, 100), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.model_id; parameters[1].Value = model.name; parameters[2].Value = model.title; parameters[3].Value = model.sort_id; parameters[4].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Hoto.Model.sys_channel GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,model_id,name,title,sort_id from dt_sys_channel "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Hoto.Model.sys_channel model = new Hoto.Model.sys_channel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["model_id"] != null && ds.Tables[0].Rows[0]["model_id"].ToString() != "") { model.model_id = int.Parse(ds.Tables[0].Rows[0]["model_id"].ToString()); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public Hoto.Model.sys_channel GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,model_id,name,title,sort_id from dt_sys_channel "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Hoto.Model.sys_channel model = new Hoto.Model.sys_channel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["model_id"] != null && ds.Tables[0].Rows[0]["model_id"].ToString() != "") { model.model_id = int.Parse(ds.Tables[0].Rows[0]["model_id"].ToString()); } if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "") { model.name = ds.Tables[0].Rows[0]["name"].ToString(); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } return model; } else { return null; } }