OleDbCommand: Execute Scalar : OleDbCommand « ADO.Net « C# / CSharp Tutorial






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

class MainClass
{
    static void Main(string[] args)
    {
        string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Northwind.mdb";
        OleDbConnection conn = new OleDbConnection(ConnectionString);

        conn.Open();
        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandText = "SELECT Count(*) FROM Customers";
        cmd.Connection = conn;

        int counter = (int)cmd.ExecuteScalar();
        
        Console.WriteLine("Total rows returned are :" + counter.ToString());
               
        conn.Close();                  
    }
}
Total rows returned are :91








32.7.OleDbCommand
32.7.1.OleDbCommand: Execute Scalar
32.7.2.Connect Table to OleDbCommand using CommandType.TableDirect
32.7.3.Execute Non Query
32.7.4.Use OLE DB Data Provider
32.7.5.Executing a Parameterized Query with OleDbCommand