程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> SQL Server 2005導入Oracle 10g的C#源碼

SQL Server 2005導入Oracle 10g的C#源碼

編輯:Oracle數據庫基礎

數據庫操作中,我們有時候需要將數據從一個數據庫導入到另一個數據庫中。本文我們主要介紹一下SQL Server 2005導入Oracle 10gC#源碼程序,希望能夠對您有所幫助。

程序代碼的參考如下:

  1. //--------------------------------------------------------------------  
  2. //AllRightsReserved,Copyright(C)2011,HairihanTECH,Ltd.  
  3. //--------------------------------------------------------------------  
  4. usingSystem.Data;  
  5. namespaceDotNet.Example  
  6. {  
  7. usingDotNet.BaseManager;  
  8. usingDotNet.DbUtilitIEs;  
  9. publicclassImportExportData  
  10. {  
  11. ///<summary> 
  12. ///導出數據庫到Oralce  
  13. ///</summary> 
  14. publicvoidExport()  
  15. {  
  16. //this.ExportTable("Items_Area");  
  17. //this.ExportTable("Items_AuditStatus");  
  18. //this.ExportTable("Items_Degree");  
  19. //this.ExportTable("Items_Duty");  
  20. //this.ExportTable("Items_Education");  
  21. //this.ExportTable("Items_Express");  
  22. //this.ExportTable("Items_Links");  
  23. //this.ExportTable("Items_MembershipLevels");  
  24. //this.ExportTable("Items_Nationality");  
  25. //this.ExportTable("Items_NewsCategory");  
  26. //this.ExportTable("Items_OnSale");  
  27. //this.ExportTable("Items_OrganizeCategory");  
  28. //this.ExportTable("Items_Party");  
  29. //this.ExportTable("Items_Pattern");  
  30. //this.ExportTable("Items_PayCategory");  
  31. //this.ExportTable("Items_PostCategory");  
  32. //this.ExportTable("Items_RoleCategory");  
  33. //this.ExportTable("Items_SalaryItemCategory");  
  34. //this.ExportTable("Items_SendCategory");  
  35. //this.ExportTable("Items_Sex");  
  36. //this.ExportTable("Items_Title");  
  37. //this.ExportTable("Items_Units");  
  38. //this.ExportTable("Items_UserAuditStates");  
  39. //this.ExportTable("Items_Wed");  
  40. //this.ExportTable("Items_WorkCategory");  
  41. //this.ExportTable("Items_WorkFlowCategorIEs");  
  42. //this.ExportTable("Items_WorkingProperty");  
  43. //this.ExportTable("Base_Businesscard");  
  44. //this.ExportTable("Base_Comment");  
  45. //this.ExportTable("Base_Contact");  
  46. //this.ExportTable("Base_ContactDetails");  
  47. //this.ExportTable("Base_Exception");  
  48. //this.ExportTable("Base_File");  
  49. //this.ExportTable("Base_Folder");  
  50. //this.ExportTable("Base_Items");  
  51. //this.ExportTable("Base_Log");  
  52. //this.ExportTable("Base_Message");  
  53. //this.ExportTable("Base_News");  
  54.  
  55. //this.ExportTable("Base_Organize");  
  56. //this.ExportTable("Base_Module","SELECT*FROMBASE_MODULEORDERBYPARENTID,ID");  
  57. //this.ExportTable("Base_PermissionItem");  
  58. //this.ExportTable("Base_Role");  
  59. //this.ExportTable("Base_Staff");  
  60. //this.ExportTable("Base_Parameter");  
  61. //this.ExportTable("Base_Project");  
  62. //this.ExportTable("Base_Permission");  
  63. //this.ExportTable("Base_PermissionScope");  
  64. this.ExportTable("Base_Sequence");  
  65. //this.ExportTable("Base_StaffOrganize");  
  66. //this.ExportTable("Base_TableColumns");  
  67. //this.ExportTable("Base_User");  
  68. //this.ExportTable("Base_UserAddress");  
  69. //this.ExportTable("Base_UserOrganize");  
  70. //this.ExportTable("Base_UserRole");  
  71. //this.ExportTable("Base_StaffOrganize");  
  72. //this.ExportTable("Base_WorkFlowActivity");  
  73. //this.ExportTable("Base_WorkFlowCurrent");  
  74. //this.ExportTable("Base_WorkFlowHistory");  
  75. //this.ExportTable("Base_WorkFlowProcess");  
  76. System.Console.ReadLine();  
  77. }  
  78. publicvoidExportTable(stringtableName)  
  79. {  
  80. ExportTable(tableName,tableName);  
  81. }  
  82. ///<summary> 
  83. ///導出一個表  
  84. ///</summary> 
  85. ///<paramnameparamname="tableName">表名</param> 
  86. ///<paramnameparamname="table">裡面的數據</param> 
  87. publicvoidExportTable(stringtableName,stringtable)  
  88. {  
  89. //這裡是獲取數據  
  90. SqlHelpersqlHelper=newSqlHelper("DataSource=localhost;InitialCatalog=UserCenterV32;IntegratedSecurity=SSPI;");  
  91. sqlHelper.Open();  
  92. DataTabledataTable=newDataTable(tableName);  
  93. if(tableName.Equals(table))  
  94. {  
  95. dataTable=sqlHelper.Fill("SELECT*FROM"+table);  
  96. }  
  97. else  
  98. {  
  99. dataTable=sqlHelper.Fill(table);  
  100. }  
  101. sqlHelper.Close();  
  102. //這裡是插入數據  
  103. OracleHelperOracleHelper=newOracleHelper("DataSource=Oracle11;user=DBO_USERCENTERV32;passWord=DBO_USERCENTERV32;");  
  104. OracleHelper.Open();  
  105. OracleHelper.BeginTransaction();  
  106. SQLBuildersqlBuilder=newSQLBuilder(OracleHelper);  
  107. try  
  108. {  
  109. //清除表數據  
  110. OracleHelper.ExecuteNonQuery("TRUNCATETABLE"+tableName);  
  111. //創建配套的序列  
  112. //OracleHelper.ExecuteNonQuery("createsequenceSEQ_"+tableName+"minvalue1maxvalue999999999999999999999999startwith1incrementby1cache20");  
  113. intr=0;  
  114. for(r=0;r<dataTable.Rows.Count;r++)  
  115. {  
  116. sqlBuilder.BeginInsert(tableName);  
  117. for(inti=0;i<dataTable.Columns.Count;i++)  
  118. {  
  119. sqlBuilder.SetValue(dataTable.Columns[i].ColumnName,dataTable.Rows[r][dataTable.Columns[i].ColumnName]);  
  120. }  
  121. sqlBuilder.EndInsert();  
  122. System.Console.WriteLine("表"+tableName+"已插入第"+r.ToString()+"行");  
  123. }  
  124. System.Console.WriteLine("--表"+tableName+"共插入"+r.ToString()+"行");  
  125. OracleHelper.CommitTransaction();  
  126. }  
  127. catch(System.Exceptionexception)  
  128. {  
  129. OracleHelper.RollbackTransaction();  
  130. System.Console.WriteLine(tableName+"--"+exception.Message);  
  131. }  
  132. finally  
  133. {  
  134. OracleHelper.Close();  
  135. }  
  136. }  

以上就是SQL Server 2005導入Oracle 10g的C#源碼程序的全部內容,本文我們就介紹到這裡了,希望本次的介紹能夠對您有所收獲!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved