using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;

namespace DataReader
{
   class Program
   {
      static void Main(string[] args)
      {
         SqlConnectionStringBuilder scb = new SqlConnectionStringBuilder();
         scb.DataSource = @".\SQLExpress";
         scb.InitialCatalog = "TestDB";
         scb.IntegratedSecurity = true;
         SqlConnection conn = new SqlConnection(scb.ConnectionString);
         conn.Open();

         SqlCommand cmd = conn.CreateCommand();
         cmd.CommandText = "SELECT * From Users";
         SqlDataReader rdr = cmd.ExecuteReader();
         while (rdr.Read())
         {
            Console.WriteLine(
              string.Format(
              "Użytkownik: {0}, imię i nazwisko: {1} {2}",
              rdr.GetString(rdr.GetOrdinal("UserName")),
              (string)rdr["FirstName"],
              rdr.GetString(rdr.GetOrdinal("LastName"))));
         }
         rdr.Close();
         conn.Close();
         Console.ReadLine();
      }
   }
}
