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