Advertisement
VladikOtez

Untitled

Oct 11th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. public class MyClass
  2. {
  3.     public int Id { get; set; }
  4.     public string LongName { get; set; }
  5. }
  6.  
  7. class Program
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         var list = new List<MyClass>();
  12.  
  13.         var builder = new OracleConnectionStringBuilder();
  14.         builder.Direct = true;
  15.         builder.Sid = "VUZWORK";
  16.         builder.UserId = "stud";
  17.         builder.Password = "-----";
  18.         builder.Server = "212.192.128.----";
  19.  
  20.         using (var connection = new OracleConnection(builder.ToString()))
  21.         {
  22.             connection.Open();
  23.             using (var command = new OracleCommand("select count(*) from SDMS.O_USE_BASE_UNITS", connection))
  24.             {
  25.  
  26.                 var n = command.ExecuteScalar() as decimal?;
  27.                 Console.WriteLine($"{n}");
  28.                 command.CommandText = "SELECT UBU_ID AS \"Id\", NAME_LONG AS \"LongName\" FROM SDMS.O_USE_BASE_UNITS WHERE ROWNUM < 10";
  29.                 var reader = command.ExecuteReader();
  30.                 while (reader.Read())
  31.                 {
  32.                     list.Add(new MyClass { Id = reader.GetInt32(0), LongName = reader.GetString(1) });
  33.                 }
  34.             }
  35.             connection.Close();
  36.         }
  37.  
  38.         foreach (var item in list)
  39.         {
  40.             Console.WriteLine($"{item.Id}\t{item.LongName}");
  41.         }
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement