Execute Scalar Example : SqlCommand Select : ADO.Net C# Examples


C# Examples » ADO.Net » SqlCommand Select »

 

Execute Scalar Example









    
using  System;
using  System.Data;
using  System.Data.SqlClient;
using  System.Collections.Generic;
using  System.Text;

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.CommandText  =  "SELECT  COUNT(*)  FROM  Customers";
                Object  countResult  =  thisCommand.ExecuteScalar();
                Console.WriteLine("Count  of  Customers  =  {0}",  countResult);

                thisConnection.Close();
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» SqlCommand Select