Пример #1
0
 /// <summary>
 /// 向数据库中添加一条记录
 /// </summary>
 /// <param name="model">要添加的实体</param>
 /// <returns>插入数据的ID</returns>
 public int Insert(CommentModel model)
 {
     #region SQL语句
     const string sql = @"
     INSERT INTO [dbo].[Comment] (
     [Content]
     ,[UId]
     ,[PId]
     ,[PostDate]
     )
     VALUES (
     @Content
     ,@UId
     ,@PId
     ,@PostDate
     );select @@IDENTITY";
     #endregion
     var res = SqlHelper.ExecuteScalar(sql,
             new SqlParameter("@Content", model.Content),
             new SqlParameter("@UId", model.UId),
             new SqlParameter("@PId", model.PId),
             new SqlParameter("@PostDate", model.PostDate)
         );
     return res == null ? 0 : Convert.ToInt32(res);
 }
Пример #2
0
 /// <summary>
 /// 根据主键ID更新一条记录
 /// </summary>
 /// <param name="model">更新后的实体</param>
 /// <returns>执行结果受影响行数</returns>
 public int Update(CommentModel model)
 {
     return _dao.Update(model);
 }
Пример #3
0
 /// <summary>
 /// 向数据库中添加一条记录
 /// </summary>
 /// <param name="model">要添加的实体</param>
 /// <returns>插入数据的ID</returns>
 public int Insert(CommentModel model)
 {
     return _dao.Insert(model);
 }
Пример #4
0
 /// <summary>
 /// 根据主键ID更新一条记录
 /// </summary>
 /// <param name="model">更新后的实体</param>
 /// <returns>执行结果受影响行数</returns>
 public int Update(CommentModel model)
 {
     #region SQL语句
     const string sql = @"
     UPDATE [dbo].[Comment]
     SET
     [Content] = @Content
     ,[UId] = @UId
     ,[PId] = @PId
     ,[PostDate] = @PostDate
     WHERE [CId] = @CId";
     #endregion
     return SqlHelper.ExecuteNonQuery(sql,
             new SqlParameter("@CId", model.CId),
             new SqlParameter("@Content", model.Content),
             new SqlParameter("@UId", model.UId),
             new SqlParameter("@PId", model.PId),
             new SqlParameter("@PostDate", model.PostDate)
         );
 }