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