SqlCommand.CommandText : SqlCommand « System.Data.SqlClient « C# / C Sharp by API






SqlCommand.CommandText

  

using System;
using System.Data;
using System.Data.SqlClient;

class ExecuteScalar
{
  public static void Main()
  {
    SqlConnection mySqlConnection =new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");
    SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
    mySqlCommand.CommandText ="SELECT COUNT(*) FROM Employee";
    mySqlConnection.Open();

    int returnValue = (int) mySqlCommand.ExecuteScalar();
    Console.WriteLine("mySqlCommand.ExecuteScalar() = " + returnValue);

    mySqlConnection.Close();
  }
}

   
    
  








Related examples in the same category

1.SqlCommand.BeginExecuteReader
2.SqlCommand.CommandType
3.SqlCommand.EndExecuteReader
4.SqlCommand.ExecuteNonQuery()
5.SqlCommand.ExecuteScalar()
6.SqlCommand.ExecuteXmlReader()
7.SqlCommand.Parameters
8.SqlCommand.Parameters.Add