Mega Code Archive

 
Categories / C# Tutorial / ADO Net
 

SQL StoredProcedure

using System; using System.Data;             using System.Data.SqlClient;   class Program {     static void Main(string[] args) {         SqlConnection thisConnection = new SqlConnection(             @"Server=(local)\sqlexpress;Integrated Security=True;" +             "Database=northwind");         thisConnection.Open();         SqlCommand thisCommand = thisConnection.CreateCommand();         thisCommand.CommandType = CommandType.StoredProcedure;         thisCommand.CommandText = "Ten Most Expensive Products";         SqlDataReader thisReader = thisCommand.ExecuteReader();         while (thisReader.Read()) {             Console.WriteLine("\t{0}\t{1}",             thisReader["TenMostExpensiveProducts"], thisReader["UnitPrice"]);         }         thisReader.Close();         thisConnection.Close();     } }