Read result set from OleDbDataReader : OleDbDataReader « ADO.Net « C# / CSharp Tutorial






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

class MainClass
{
   static void Main(string[] args)
   {
      string connString = "provider=sqloledb;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";

      string sql = @"select * from employee";

      OleDbConnection conn = null;
      OleDbDataReader reader = null;

      try
      {
         conn = new OleDbConnection(connString);
         conn.Open();

         OleDbCommand cmd = new OleDbCommand(sql, conn);
         reader = cmd.ExecuteReader();

         Console.WriteLine("Querying database {0} with query {1}\n", conn.Database, cmd.CommandText );

         while(reader.Read()) {
            Console.WriteLine("{0} | {1}", reader["FirstName"].ToString().PadLeft(10), reader[1].ToString().PadLeft(10));
         }
      }
      catch (Exception e)
      {
         Console.WriteLine("Error: " + e);
      }
      finally
      {
         reader.Close();
         conn.Close();
      }
   }
}








32.11.OleDbDataReader
32.11.1.Read result set from OleDbDataReader
32.11.2.Use to OleDbDataReader retrieve data
32.11.3.OleDbDataAdapter and SqlDataAdapter: UpdateOleDbDataAdapter and SqlDataAdapter: Update
32.11.4.Typed Accessors
32.11.5.Get SchemaTable from OleDbDataReader