Guest User

Untitled

a guest
Jan 4th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.OleDb;
  6. namespace conexaoAccess
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             OleDbConnection conexao = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Victor\Documents\exemplo.mdb");
  13.             OleDbCommand sql = new OleDbCommand("select * from bairro", conexao);
  14.             try
  15.             {
  16.                 conexao.Open();
  17.                 OleDbDataReader lendo_dados = sql.ExecuteReader();  
  18.                 while (lendo_dados.Read())
  19.                 {
  20.                     Console.WriteLine(lendo_dados.GetString(1));
  21.                     Console.WriteLine(lendo_dados.GetString(2) + "\n");
  22.                 }
  23.                 Console.WriteLine("Fim da lista");
  24.                 Console.ReadKey();
  25.                 lendo_dados.Close();
  26.                 conexao.Close();
  27.             }
  28.             catch (OleDbException erro_oledb)
  29.             {
  30.                 Console.WriteLine(erro_oledb.Message);
  31.              
  32.             }
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment