public static int Save(RankInfo rank) { int id; if (rank.ID <= 0) { id = RankDao.Add(rank); } else { id = RankDao.Update(rank) ? rank.ID : 0; } return id; }
public static bool Update(RankInfo rank) { SqlParameter[] parameters = new SqlParameter[2]; parameters[0] = new SqlParameter("@ID", SqlDbType.Int); parameters[0].Value = rank.ID; parameters[1] = new SqlParameter("@Name", SqlDbType.VarChar, 30); parameters[1].Value = rank.Name; StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE RankInfo SET Rank = @Name"); sql.AppendLine("WHERE ID = @ID"); int rowCount = helper.ExecuteNonQuery(sql.ToString(), parameters.ToArray()); return rowCount > 0; }
public static int Add(RankInfo rank) { SqlParameter[] parameters = new SqlParameter[1]; parameters[0] = new SqlParameter("@Name", SqlDbType.VarChar, 30); parameters[0].Value = rank.Name; StringBuilder sql = new StringBuilder(); sql.AppendLine("DECLARE @ID int"); sql.AppendLine("INSERT INTO RankInfo (Rank)"); sql.AppendLine("VALUES (@Name)"); sql.AppendLine("SET @ID = SCOPE_IDENTITY()"); sql.AppendLine("SELECT @ID"); int newID = (int)helper.ExecuteScalar(sql.ToString(), parameters); return newID; }