C#
В файле Program.cs напишем код:
using System;
// подключаем SQL ADO.NET
using Microsoft.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// connection string
string connectionString = @"Data Source=EVGENI; Initial Catalog=MyDatabase1; Integrated Security=True";
// connect to db
using (SqlConnection connection = new SqlConnection(connectionString))
{
// open db
connection.Open();
// init sql Command
using (SqlCommand command = new SqlCommand())
{
// connection
command.Connection = connection;
// Count
command.CommandText = "SELECT COUNT(*) from Books";
object result1 = command.ExecuteScalar();
// выводим на экран
Console.WriteLine("Число записей={0}", result1);
// MIN
command.CommandText = "SELECT MIN(Price) from Books";
object result2 = command.ExecuteScalar();
// выводим на экран
Console.WriteLine("MIN Цена={0}", result2);
// MAX
command.CommandText = "SELECT MAX(Price) from Books";
object result3 = command.ExecuteScalar();
// выводим на экран
Console.WriteLine("MAX Цена={0}", result3);
// SUM
command.CommandText = "SELECT SUM(Price) from Books";
object result4 = command.ExecuteScalar();
// выводим на экран
Console.WriteLine("SUM Цена={0}", result4);
}
}
}
}
}