How to execute a TableDirect command : OleDbCommand « Database ADO.net « C# / C Sharp






How to execute a TableDirect command


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

class ExecuteTableDirect
{
  public static void Main()
  {
    OleDbConnection myOleDbConnection =new OleDbConnection("provider=sqloledb;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
    OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();

    myOleDbCommand.CommandType = CommandType.TableDirect;

    myOleDbCommand.CommandText = "Employee";

    myOleDbConnection.Open();

    OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();

    for (int count = 1; count <= 2; count++)
    {
      myOleDbDataReader.Read();
      Console.WriteLine("myOleDbDataReader[\" ID\"] = " +
        myOleDbDataReader["ID"]);
      Console.WriteLine("myOleDbDataReader[\" FirstName\"] = " +
        myOleDbDataReader["FirstName"]);
      Console.WriteLine("myOleDbDataReader[\" LastName\"] = " +
        myOleDbDataReader["LastName"]);
    }
    myOleDbDataReader.Close();
    myOleDbConnection.Close();
  }
}


           
       








Related examples in the same category

1.Execute aggregate function: sumExecute aggregate function: sum
2.Get column averageGet column average
3.Get max column valueGet max column value
4.Get count value from a select queryGet count value from a select query
5.Between certain dates
6.Delete database records through OleDbCommand and verify the results
7.Create table and populate data
8.Pass parameter to OleDbCommandPass parameter to OleDbCommand