using System;
using System.Data;
using System.Data.SqlClient;
class MainClass
{
public static void Main()
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = @"Data Source = .\sqlexpress;Database = Northwind; Integrated Security=SSPI";
con.Open();
string category = "Seafood";
string year = "1999";
using (SqlCommand com = con.CreateCommand())
{
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "SalesByCategory";
com.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value =
category;
com.Parameters.Add("@OrdYear", SqlDbType.NVarChar).Value = year;
using (IDataReader reader = com.ExecuteReader())
{
Console.WriteLine("Sales By Category ({0}).", year);
while (reader.Read())
{
Console.WriteLine(" {0} = {1}",
reader["ProductName"],
reader["TotalPurchase"]);
}
}
}
}
}
}