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,如需转载请自行联系原作者

相关文章
|
2月前
|
关系型数据库 MySQL 数据库
OceanBase数据库常见问题之脚本执行失败如何解决
OceanBase 是一款由阿里巴巴集团研发的企业级分布式关系型数据库,它具有高可用、高性能、可水平扩展等特点。以下是OceanBase 数据库使用过程中可能遇到的一些常见问题及其解答的汇总,以帮助用户更好地理解和使用这款数据库产品。
|
1天前
|
移动开发 前端开发 数据库
几种经典的支持数据库的表单设计器参考
几种经典的支持数据库的表单设计器参考
|
3天前
|
Oracle Unix 关系型数据库
AIX数据库启动和停止脚本
AIX数据库启动和停止脚本
10 1
|
3天前
|
SQL 数据库 数据安全/隐私保护
修改SAP数据库用户密码的参考
修改SAP数据库用户密码的参考
|
6天前
|
SQL 存储 Oracle
C#利用IDbCommand实现通用数据库脚本执行程序
C#利用IDbCommand实现通用数据库脚本执行程序
|
13天前
|
弹性计算 NoSQL Shell
一键安装 MongoDB 数据库脚本
【4月更文挑战第29天】
16 4
|
2天前
|
关系型数据库 MySQL 数据库
docker MySQL删除数据库时的错误(errno: 39)
docker MySQL删除数据库时的错误(errno: 39)
10 0
|
2天前
|
关系型数据库 MySQL 数据库连接
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
|
3天前
|
存储 Oracle 关系型数据库
oracle 数据库 迁移 mysql数据库
将 Oracle 数据库迁移到 MySQL 是一项复杂的任务,因为这两种数据库管理系统具有不同的架构、语法和功能。
15 0
|
11天前
|
关系型数据库 MySQL Linux
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)
【MySQL-10】数据库函数-案例演示【字符串/数值/日期/流程控制函数】(代码演示&可cv代码)