vakho

ADO LAB2

Sep 27th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using System.Data.SqlClient;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             SqlConnection connection = new SqlConnection();
  15.             connection.ConnectionString = "Server=LAB-418-09-PC; Database=master; Integrated Security=True";
  16.             connection.Open();
  17.             Console.WriteLine(connection.State);
  18.  
  19.             SqlCommand command = new SqlCommand();
  20.             command.Connection = connection;
  21.             command.CommandText = "SELECT * FROM [master].[dbo].[spt_values] ORDER BY number DESC";
  22.             SqlDataReader reader = command.ExecuteReader();
  23.             while (reader.Read())
  24.             {
  25.                 Console.WriteLine(reader["name"].ToString());
  26.             }
  27.             reader.Close();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment