Facebook
From Dawid P, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 261
  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.SqlClient;
  7. using System.Data;
  8.  
  9. namespace polaczeni_z_baza_danych_SQLserv
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             try
  16.    {
  17.    SqlConnection polaczenie = new SqlConnection(@"Data source=172.30.53.163;
  18.                                                             database=Marcin;
  19.                                                             User id=sa;
  20.                                                             Password=Qwerty78;
  21.                                                                TrustServerCertificate= true;
  22.                                                                Encrypt = true");
  23.    polaczenie.Open();
  24.    SqlCommand komendaSQL = polaczenie.CreateCommand();
  25.    komendaSQL.CommandText = "SELECT * FROM pchorek";
  26.    SqlDataReader czytnik = komendaSQL.ExecuteReader();
  27.  
  28.    Console.WriteLine("Wiersze tabeli:");
  29.     while (czytnik.Read())
  30.      {                  
  31.      Console.WriteLine(czytnik ["Imię"].ToString() + "   " + czytnik["Nazwisko"].ToString() + "   " + czytnik["Stopień"].ToString() + "   " + czytnik["płeć"].ToString());
  32.      }
  33.   czytnik.Close();
  34.   polaczenie.Close();
  35.                
  36.   Console.ReadKey();
  37.     }
  38.  
  39.   catch (SqlException e)
  40.      {
  41.      
  42.       Console.WriteLine(e.Message);
  43.       Console.ReadKey();
  44.      }
  45.  }
  46.         }
  47.     }
  48.