How to connect to Excel 2016 with oledb.

  • Thread starter Thread starter The original Stinger
  • Start date Start date
T

The original Stinger

Guest
I'm trying to connect to an excel sheet office 2016.
But I always get an error.
What's wrong ?



private static String filePath = @"C:\Users\oliver\Documents\klantenformulier.xlsx";

private string connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0 Xml;Data Source={0}; Extended Properties='Excel 12.0; HDR=Yes'", filePath);

//Is there something wrong with the above connection string ?

//I use this code to test the connection:
//I always get the exception after oleDBConnection.open();


public void connectieMaken()
{

OleDbConnection oleDbConnection = new OleDbConnection(this.connectionString);
try
{
oleDbConnection.Open();
MessageBox.Show("Connection Successful");
}
catch (Exception ex)
{
MessageBox.Show("Connection failed :" + oleDbConnection.ConnectionString);
}

}

Continue reading...
 
Back
Top