***Add the namspace ==> using System.Data.OleDb;***
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection Connection;
// The file path's goes with double slash
Connection = new OleDbConnection
(
"provider=Microsoft.Jet.OLEDB.4.0;data source=C:\\test.xls;Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\""
);
Connection.Open();
// Select which page is going to upload
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", Connection);
DataTable table = new DataTable();
// Fill
Adapter.Fill(table);
this.dataGridView1.DataSource = table.DefaultView;
}
No comments:
Post a Comment