Since you did not respond to my comment above, I am posting a solution for both.
You are Missing ' in Extended Properties
For Excel 2003 try this ( TRIED AND TESTED )
private void button1_Click(object sender, EventArgs e) { String name = "Items"; String constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:\\Sample.xls" + ";Extended Properties='Excel 8.0;HDR=YES;';"; OleDbConnection con = new OleDbConnection(constr); OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con); con.Open(); OleDbDataAdapter sda = new OleDbDataAdapter(oconn); DataTable data = new DataTable(); sda.Fill(data); grid_items.DataSource = data; }
By the way, I have not worked with Jet for a long time. I am using ACE now.
private void button1_Click(object sender, EventArgs e) { String name = "Items"; String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "C:\\Sample.xls" + ";Extended Properties='Excel 8.0;HDR=YES;';"; OleDbConnection con = new OleDbConnection(constr); OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con); con.Open(); OleDbDataAdapter sda = new OleDbDataAdapter(oconn); DataTable data = new DataTable(); sda.Fill(data); grid_items.DataSource = data; }

For Excel 2007+
private void button1_Click(object sender, EventArgs e) { String name = "Items"; String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "C:\\Sample.xlsx" + ";Extended Properties='Excel 12.0 XML;HDR=YES;';"; OleDbConnection con = new OleDbConnection(constr); OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con); con.Open(); OleDbDataAdapter sda = new OleDbDataAdapter(oconn); DataTable data = new DataTable(); sda.Fill(data); grid_items.DataSource = data; }
source share