/// <summary> /// 根据主键ID更新一条记录 /// </summary> /// <param name="model">更新后的实体</param> /// <returns>执行结果受影响行数</returns> public int Update(BookComment model) { #region SQL语句 const string sql = @" UPDATE [dbo].[BookComment] SET [Msg] = @Msg ,[CreateDateTime] = @CreateDateTime ,[BookId] = @BookId WHERE [Id] = @Id"; #endregion return(SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@Id", model.Id), new SqlParameter("@Msg", model.Msg), new SqlParameter("@CreateDateTime", model.CreateDateTime), new SqlParameter("@BookId", model.BookId) )); }
/// <summary> /// 向数据库中添加一条记录 /// </summary> /// <param name="model">要添加的实体</param> /// <returns>插入数据的ID</returns> public int Insert(BookComment model) { #region SQL语句 const string sql = @" INSERT INTO [dbo].[BookComment] ( [Msg] ,[CreateDateTime] ,[BookId] ) VALUES ( @Msg ,@CreateDateTime ,@BookId );select @@IDENTITY"; #endregion var res = SqlHelper.ExecuteScalar(sql, new SqlParameter("@Msg", model.Msg), new SqlParameter("@CreateDateTime", model.CreateDateTime), new SqlParameter("@BookId", model.BookId) ); return(res == null ? 0 : Convert.ToInt32(res)); }