Connect Table to OleDbCommand using CommandType.TableDirect : OleDbCommand : ADO.Net C# Examples


C# Examples » ADO.Net » OleDbCommand »

 

Connect Table to OleDbCommand using CommandType.TableDirect









    
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);

        OleDbCommand  cmd  =  new  OleDbCommand();
        cmd.Connection  =  conn;
        cmd.CommandText  =  "Customers";

        cmd.CommandType  =  CommandType.TableDirect;
              
        conn.Open();
        OleDbDataReader  reader  =  cmd.ExecuteReader();

        Console.WriteLine("Customer  Id,  Contact  Name,  Company  Name");
                
        while  (reader.Read())
        {
            Console.Write(reader["CustomerID"].ToString());
            Console.Write(",  "+  reader["ContactName"].ToString());
            Console.WriteLine(",  "+  reader["CompanyName"].ToString());
        }
        
        reader.Close();
        conn.Close();                                    
        }
}
    
   
  
   



Output

Customer Id, Contact Name, Company Name
ALFKI, Maria Anders, Alfreds Futterkiste
ANATR, Ana Trujillo, Ana Trujillo Emparedados y helados
ANTON, Antonio Moreno, Antonio Moreno Taquer?
AROUT, Thomas Hardy, Around the Horn
BERGS, Christina Berglund, Berglunds snabbk?p
BLAUS, Hanna Moos, Blauer See Delikatessen
WOLZA, Zbyszek Piestrzeniewicz, Wolski  Zajazd
...
...


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo ADO.Net
» OleDbCommand