-Annie-

CloseConnectionSQL

Oct 22nd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.45 KB | None | 0 0
  1. USING System;
  2. USING System.Collections.Generic;
  3. USING System.DATA.SqlClient;
  4. USING System.Linq;
  5. USING System.Text;
  6. USING System.Threading.Tasks;
  7.  
  8. namespace Selection
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string connectionString = "Server=ACER-5253G\\SQLEXPRESS; Database=SoftUni; Trusted_Connection=True";
  15.             SqlConnection connection = NEW SqlConnection(connectionString);
  16.             connection.OPEN();
  17.             USING (connection)
  18.             {
  19.                 string selectionCommandString = "SELECT * FROM JudgeFails";
  20.                 SqlCommand command = NEW SqlCommand(selectionCommandString, connection);
  21.                 SqlDataReader reader = command.ExecuteReader();
  22.                 while (reader.READ())
  23.                 {
  24.                     FOR (INT i = 0; i < reader.FieldCount; i++)
  25.                     {
  26.                         Console.WriteLine($"{reader[i]} ");
  27.                     }
  28.                     Console.WriteLine();
  29.                 }
  30.                 reader.Close();
  31.  
  32.                 SqlDataReader reader2 = command.ExecuteReader();
  33.                 while (reader2.READ())
  34.                 {
  35.                     FOR (INT i = 0; i < reader2.FieldCount; i++)
  36.                     {
  37.                         Console.WriteLine($"{reader2[i]} ");
  38.                     }
  39.                     Console.WriteLine();
  40.                 }
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment