string excelFilePath = "sunny.xlsx"; string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFilePath + ";Extended Properties=\"Excel 12.0;HDR=NO\""; OleDbConnection excelOledbConObj = new OleDbConnection(); excelOledbConObj.ConnectionString = connectionString; DataTable excelDataTable = new DataTable(); OleDbCommand oledbCmdObj = new OleDbCommand(); oledbCmdObj.Connection = excelOledbConObj; try { oledbCmdObj.CommandText = "SELECT * FROM [Sheet1$]"; OleDbDataAdapter oldataAdapterObj = new OleDbDataAdapter(oledbCmdObj); oldataAdapterObj.Fill(excelDataTable); } catch (OleDbException ex) { Response.Write(ex.Message); }
//try to find out in the following way OleDbConnection Con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://Documents and Settings//Admin//My Documents//Downloads//MyReport2.xls;Extended Properties=Excel 8.0;"); Con.Open(); OleDbCommand Cmd = new OleDbCommand("Select * from [Sheet1$]", Con); OleDbDataAdapter dt = new OleDbDataAdapter(Cmd); DataSet ds = new DataSet(); dt.Fill(ds); Con.Close(); //Or you can try this OleDbConnection Con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Admin\Desktop\MyReport1.xls;Extended Properties=Excel 8.0;"
keep ur excel in debug folder
string excelFilePath = ".\\sunny.xlsx";
excelOledbConObj.Open();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)