Code snippet: Read data from Access Database in C#

Read data from Access Database in C#

1:  private static void ReadFromAccess(string accessDbPath)  
2:      {  
3:        string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= {0}",accessDbPath);  
4:        using (OleDbConnection con = new OleDbConnection(connection))  
5:        {  
6:          try  
7:          {  con.Open();  
8:            OleDbCommand cmd = new OleDbCommand("SELECT * FROM Table_NAME", con);  
9:            OleDbDataReader reader = cmd.ExecuteReader();  
10:    
11:            while (reader.Read())  
12:            {  
13:              Console.WriteLine(reader.GetString(0));  
14:            }  
15:    
16:          }catch(Exception ex)  
17:          {  
18:            Console.WriteLine(ex.Message);  
19:          }finally  
20:          {  
21:            con.Close();  
22:          }  
23:        }  
24:      }  

Comments

Popular posts from this blog

Prevent WPF Global Keyboard Hook from stops working after hitting keys a while C# .NET

Generate ArcGIS Token By URL Request From ArcGIS Portal, Federated Environment , ESRI JS API and Angular snippets

Solution: IntelliJ not recognizing a particular file correctly, instead its stuck as a text file