Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data.OracleClient;
  7. using System.Data;
  8. using System.Collections;
  9.  
  10. namespace test
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string query1 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME1'";
  17. string query2 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME2'";
  18. //string query2 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME'";
  19. ArrayList columns1 = getcolumnname(query1, ";uid=xxxxxx;pwd=oooooo");
  20. ArrayList columns2 = getcolumnname(query2, ";uid=xxxxxx;pwd=oooooo");
  21. //ArrayList columns2 = getcolumnname(query2, ";uid=xxxxxx;pwd=wwwwwww");
  22. ArrayList diff = new ArrayList();
  23. ArrayList same = new ArrayList();
  24.  
  25. if (columns1[0].ToString() == columns2[0].ToString()) same.Add(columns1[0]);
  26.  
  27.  
  28. foreach (string a in columns1)
  29. {
  30.  
  31.  
  32. if (columns2.Contains(a) )
  33. same.Add(a);
  34. else
  35. diff.Add(a);
  36.  
  37. }
  38. Console.Read();
  39. //for each
  40. //System.IO.File.WriteAllText(@"WriteText.txt", text);
  41. }
  42.  
  43. static ArrayList getcolumnname(string query,string UID_PWD)
  44. {
  45. string connectionString = @"server=(DESCRIPTION = (ADDRESS_LIST =
  46. (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.999)(PORT = 1521))
  47. )
  48. (CONNECT_DATA =
  49. (SID = TESTxxxxx)
  50. (SERVER = DEDICATED)
  51. )
  52. )"+ UID_PWD;
  53. ArrayList RecordsInfo = new ArrayList();
  54. using (OracleConnection connection = new OracleConnection(connectionString))
  55. {
  56. try
  57. {
  58. connection.Open();
  59. //Console.WriteLine("ServerVersion: " + connection.ServerVersion
  60. // + "\nDataSource: " + connection.DataSource);
  61. OracleCommand command = connection.CreateCommand();
  62. command.CommandText = query;
  63. OracleDataReader reader = command.ExecuteReader();
  64.  
  65. if (reader.HasRows)
  66. {
  67.  
  68. while (reader.Read())
  69. {
  70. RecordsInfo.Add(reader["column_name"].ToString());
  71. //Console.WriteLine(reader.GetString(0));
  72. }
  73. }
  74. else
  75. {
  76. Console.WriteLine("No rows found.");
  77. }
  78. reader.Close();
  79.  
  80. }
  81. finally
  82. {
  83. connection.Close();
  84. }
  85.  
  86. }
  87.  
  88. return RecordsInfo;
  89.  
  90. }
  91.  
  92.  
  93.  
  94. private static string GetConnectionString()
  95. {
  96. // To avoid storing the connection string in your code,
  97. // you can retrieve it from a configuration file.
  98. return "Server=OracleDemo;Integrated Security=true";
  99. }
  100.  
  101. }
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement