Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.OracleClient;
- using System.Data;
- using System.Collections;
- namespace test
- {
- class Program
- {
- static void Main(string[] args)
- {
- string query1 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME1'";
- string query2 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME2'";
- //string query2 = @"select t.column_name from all_tab_columns t where t.TABLE_NAME = 'TABLE_NAME'";
- ArrayList columns1 = getcolumnname(query1, ";uid=xxxxxx;pwd=oooooo");
- ArrayList columns2 = getcolumnname(query2, ";uid=xxxxxx;pwd=oooooo");
- //ArrayList columns2 = getcolumnname(query2, ";uid=xxxxxx;pwd=wwwwwww");
- ArrayList diff = new ArrayList();
- ArrayList same = new ArrayList();
- if (columns1[0].ToString() == columns2[0].ToString()) same.Add(columns1[0]);
- foreach (string a in columns1)
- {
- if (columns2.Contains(a) )
- same.Add(a);
- else
- diff.Add(a);
- }
- Console.Read();
- //for each
- //System.IO.File.WriteAllText(@"WriteText.txt", text);
- }
- static ArrayList getcolumnname(string query,string UID_PWD)
- {
- string connectionString = @"server=(DESCRIPTION = (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.999)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SID = TESTxxxxx)
- (SERVER = DEDICATED)
- )
- )"+ UID_PWD;
- ArrayList RecordsInfo = new ArrayList();
- using (OracleConnection connection = new OracleConnection(connectionString))
- {
- try
- {
- connection.Open();
- //Console.WriteLine("ServerVersion: " + connection.ServerVersion
- // + "\nDataSource: " + connection.DataSource);
- OracleCommand command = connection.CreateCommand();
- command.CommandText = query;
- OracleDataReader reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- while (reader.Read())
- {
- RecordsInfo.Add(reader["column_name"].ToString());
- //Console.WriteLine(reader.GetString(0));
- }
- }
- else
- {
- Console.WriteLine("No rows found.");
- }
- reader.Close();
- }
- finally
- {
- connection.Close();
- }
- }
- return RecordsInfo;
- }
- private static string GetConnectionString()
- {
- // To avoid storing the connection string in your code,
- // you can retrieve it from a configuration file.
- return "Server=OracleDemo;Integrated Security=true";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement