C#.NET通用权限管理在DB2数据库上运行的脚本参考 - 通过程序将数据导入到目标数据库中

简介:

参考代码如下:

// --------------------------------------------------------------------
//  All Rights Reserved , Copyright (C) 2011 , Hairihan TECH, Ltd. 
// --------------------------------------------------------------------

using  System.Data;

namespace  DotNet.Example
{
using  DotNet.BaseManager;
using  DotNet.DbUtilities;

public class  ImportExportData
   {
/// <summary>
///  导出数据库到Oralce
/// </summary>
public void  Export()
       {
this .ExportTable( " Items_Nationality " );
this .ExportTable( " Items_Area " );
this .ExportTable( " Items_AuditStatus " );
this .ExportTable( " Items_Degree " );
this .ExportTable( " Items_Duty " );
this .ExportTable( " Items_Education " );
this .ExportTable( " Items_Express " );
this .ExportTable( " Items_Links " );
this .ExportTable( " Items_MembershipLevels " );
this .ExportTable( " Items_NewsCategory " );
this .ExportTable( " Items_OnSale " );
this .ExportTable( " Items_OrganizeCategory " );
this .ExportTable( " Items_Party " );
this .ExportTable( " Items_Pattern " );
this .ExportTable( " Items_PayCategory " );
this .ExportTable( " Items_PostCategory " );
this .ExportTable( " Items_RoleCategory " );
this .ExportTable( " Items_SalaryItemCategory " );
this .ExportTable( " Items_SendCategory " );
this .ExportTable( " Items_Gender " );
this .ExportTable( " Items_Title " );
this .ExportTable( " Items_Units " );
this .ExportTable( " Items_Wed " );
this .ExportTable( " Items_AuditStatus " );
this .ExportTable( " Items_WorkCategory " );
this .ExportTable( " Items_WorkFlowCategories " );
this .ExportTable( " Items_WorkingProperty " );
this .ExportTable( " Base_Businesscard " );
this .ExportTable( " Base_Comment " );
this .ExportTable( " Base_Contact " );
this .ExportTable( " Base_ContactDetails " );
this .ExportTable( " Base_Exception " );
this .ExportTable( " Base_File " );
this .ExportTable( " Base_Folder " );
this .ExportTable( " Base_Items " );
this .ExportTable( " Base_Log " );
this .ExportTable( " Base_Message " );
this .ExportTable( " Base_News " );

this .ExportTable( " Base_Organize " );
this .ExportTable( " Base_Module " "  SELECT * FROM BASE_MODULE ORDER BY PARENTID, ID  " );
this .ExportTable( " Base_PermissionItem " );
this .ExportTable( " Base_Role " );
this .ExportTable( " Base_Staff " );

this .ExportTable( " Base_Parameter " );
this .ExportTable( " Base_Project " );
this .ExportTable( " Base_Permission " );
this .ExportTable( " Base_PermissionScope " );

this .ExportTable( " Base_Sequence " );

this .ExportTable( " Base_StaffOrganize " );
this .ExportTable( " Base_TableColumns " );
this .ExportTable( " Base_User " );
this .ExportTable( " Base_UserAddress " );
this .ExportTable( " Base_UserOrganize " );
this .ExportTable( " Base_UserRole " );
this .ExportTable( " Base_StaffOrganize " );

/*
           this.ExportTable("Base_WorkFlowActivity");
           this.ExportTable("Base_WorkFlowCurrent");
           this.ExportTable("Base_WorkFlowHistory");
           this.ExportTable("Base_WorkFlowProcess");
*/

           System.Console.ReadLine();
       }

public void  ExportTable( string  tableName)
       {
           ExportTable(tableName.ToUpper(), tableName.ToUpper());
       }

/// <summary>
///  导出一个表
/// </summary>
/// <param name="tableName"> 表名 </param>
/// <param name="table"> 里面的数据 </param>
public void  ExportTable( string  tableName,  string  table)
       {
//  这里是获取目标数据表的方法
           IDbHelper sourceDB  = new  SqlHelper( " Data Source=192.168.0.121;Initial Catalog=UserCenterV36;User Id = sa ; Password = xx; " );
           sourceDB.Open();
           DataTable dataTable 
= new  DataTable(tableName);
if  (tableName.Equals(table))
           {
               dataTable 
=  sourceDB.Fill( " SELECT * FROM  " +  table);
           }
else
           {
               dataTable 
=  sourceDB.Fill(table);
           }
           sourceDB.Close();

//  这里是目标表的数据插入处理
//  IDbHelper targetDB = new OracleHelper("Data Source=KANGFU;user=usercenter;password=xx;");
           IDbHelper targetDB  = new  DB2Helper( " Database=UCV36;UserID=JIRIGALA;Password=xx;Server=JIRIGALA-PC; " );
           targetDB.Open();
           targetDB.BeginTransaction();
           SQLBuilder sqlBuilder 
= new  SQLBuilder(targetDB);
try
           {
//  清除表数据
//  targetDB.ExecuteNonQuery(" TRUNCATE TABLE " + tableName);
               targetDB.ExecuteNonQuery( "  DELETE FROM  " +  tableName);
//  创建配套的序列
//  targetDB.ExecuteNonQuery("create sequence SEQ_" + tableName.ToUpper() + " as bigint start with 1000000 increment by 1 minvalue 10000 maxvalue 99999999999999999 cycle cache 20 order");
//  targetDB.ExecuteNonQuery("create sequence SEQ_" + tableName + " minvalue 1 maxvalue 999999999999999999999999 start with 1 increment by 1 cache 20");
int  r  = 0 ;
for  (r  = 0 ; r  <  dataTable.Rows.Count; r ++ )
               {
                   sqlBuilder.BeginInsert(tableName);
for  ( int  i  = 0 ; i  <  dataTable.Columns.Count; i ++ )
                   {
                       sqlBuilder.SetValue(dataTable.Columns[i].ColumnName, dataTable.Rows[r][dataTable.Columns[i].ColumnName]);
                   }
                   sqlBuilder.EndInsert();
//  System.Console.WriteLine("表 " + tableName + " 已插入第 " + r.ToString() + " 行");
               }
               System.Console.WriteLine(
"  - - 表  " +  tableName  + "  共插入  " +  r.ToString()  + "  行 " );
               targetDB.CommitTransaction();
           }
catch  (System.Exception exception)
           {
//  targetDB.RollbackTransaction();
               System.Console.WriteLine(tableName  + "  --  " +  exception.Message);
           }
finally
           {
               targetDB.Close();
           }
       }
   }
}





本文转自 jirigala 51CTO博客,原文链接:http://blog.51cto.com/2347979/1197383,如需转载请自行联系原作者

相关文章
|
1月前
|
SQL 关系型数据库 MySQL
阿里云RDS云数据库全解析:产品功能、收费标准与活动参考
与云服务器ECS一样,关系型数据库RDS也是很多用户上云必买的热门云产品之一,阿里云的云数据库RDS主要包含RDS MySQL、RDS SQL Server、RDS PostgreSQL、RDS MariaDB等几个关系型数据库,并且提供了容灾、备份、恢复、监控、迁移等方面的全套解决方案,帮助您解决数据库运维的烦恼。本文为大家介绍阿里云的云数据库 RDS主要产品及计费方式、收费标准以及活动等相关情况,以供参考。
|
10月前
|
C# 开发工具 C++
code runner 运行C#项目
本文介绍了如何修改Code Runner设置使 Visual Studio Code (VS Code) 能直接运行完整的 C# 项目。传统方式依赖 cscript 工具,仅支持 .csx 文件,功能受限且已停止维护。新配置使用 `dotnet run` 命令,结合一系列炫酷的cmd指令,将指令定位到具体的csproj文件上进行运行。
525 38
|
7月前
|
SQL 小程序 API
如何运用C#.NET技术快速开发一套掌上医院系统?
本方案基于C#.NET技术快速构建掌上医院系统,结合模块化开发理念与医院信息化需求。核心功能涵盖用户端的预约挂号、在线问诊、报告查询等,以及管理端的排班管理和数据统计。采用.NET Core Web API与uni-app实现前后端分离,支持跨平台小程序开发。数据库选用SQL Server 2012,并通过读写分离与索引优化提升性能。部署方案包括Windows Server与负载均衡设计,确保高可用性。同时针对API差异、数据库老化及高并发等问题制定应对措施,保障系统稳定运行。推荐使用Postman、Redgate等工具辅助开发,提升效率与质量。
290 0
|
11月前
|
开发框架 搜索推荐 算法
一个包含了 50+ C#/.NET编程技巧实战练习教程
一个包含了 50+ C#/.NET编程技巧实战练习教程
337 18
|
11月前
|
开发框架 人工智能 .NET
C#/.NET/.NET Core拾遗补漏合集(24年12月更新)
C#/.NET/.NET Core拾遗补漏合集(24年12月更新)
174 6
|
11月前
|
开发框架 算法 .NET
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
C#/.NET/.NET Core技术前沿周刊 | 第 15 期(2024年11.25-11.30)
180 6
|
11月前
|
开发框架 Cloud Native .NET
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
C#/.NET/.NET Core技术前沿周刊 | 第 16 期(2024年12.01-12.08)
180 6
|
2月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
128 3
|
2月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
2月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。

热门文章

最新文章

下一篇
oss云网关配置