شما برای این کار باید connectionstring تون رو عوض کنید
فکر کنم کد زیر مشکلتون رو با هر 2 نوع فرمت 2003 و 2007 حل کنه
private void LoadFile(DataGridView dg, string filename, string ssheet)
{
string cs = "";
if (System.IO.Path.GetExtension(filename) == ".xlsx")
{
cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename+ ";Extended Properties='Excel 12.0;'";
}
else
{
cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties='Excel 8.0;'";
}
try
{
OleDbConnection cn = new OleDbConnection(cs);
if (!System.IO.File.Exists(filename))
{
MessageBox.Show("Not Found!");
}
OleDbDataAdapter adapter = new OleDbDataAdapter("Select * From [" + ssheet + "$]", cs);
DataSet ds = new DataSet();
adapter.Fill(ds);
dg.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}