/// <summary> /// 增加一条数据 /// </summary> public int Add(CdHotelManage.Model.modes model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into modes("); strSql.Append("moshi_name,Reanker,sort)"); strSql.Append(" values ("); strSql.Append("@moshi_name,@Reanker,@sort)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@moshi_name", SqlDbType.NVarChar, 50), new SqlParameter("@Reanker", SqlDbType.NVarChar), new SqlParameter("@sort", SqlDbType.Int, 4) }; parameters[0].Value = model.moshi_name; parameters[1].Value = model.Reanker; parameters[2].Value = model.sort; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(CdHotelManage.Model.modes model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update modes set "); strSql.Append("moshi_name=@moshi_name,"); strSql.Append("Reanker=@Reanker,"); strSql.Append("sort=@sort"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@moshi_name", SqlDbType.NVarChar, 50), new SqlParameter("@Reanker", SqlDbType.NVarChar), new SqlParameter("@sort", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.moshi_name; parameters[1].Value = model.Reanker; parameters[2].Value = model.sort; parameters[3].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CdHotelManage.Model.modes GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,moshi_name,Reanker,sort from modes "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; CdHotelManage.Model.modes model = new CdHotelManage.Model.modes(); 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]["moshi_name"] != null && ds.Tables[0].Rows[0]["moshi_name"].ToString() != "") { model.moshi_name = ds.Tables[0].Rows[0]["moshi_name"].ToString(); } if (ds.Tables[0].Rows[0]["Reanker"] != null && ds.Tables[0].Rows[0]["Reanker"].ToString() != "") { model.Reanker = ds.Tables[0].Rows[0]["Reanker"].ToString(); } if (ds.Tables[0].Rows[0]["sort"] != null && ds.Tables[0].Rows[0]["sort"].ToString() != "") { model.sort = int.Parse(ds.Tables[0].Rows[0]["sort"].ToString()); } return(model); } else { return(null); } }