Reputation: 20078
UPDATE:
after updating the correct path, I'm getting the new error which says
"External table is not in the expected format."
I'm not sure what is wrong with this code and I'm trying to read the excel sheet and below is my code and getting the following error.
OleDbConnection oledbConn = new OleDbConnection();
string path = Path.GetFullPath(Server.MapPath("~/InformationNew.xlsx"));
oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter oleda = new OleDbDataAdapter();
DataSet ds = new DataSet();
cmd.Connection = oledbConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT [epic],[desc] FROM [Sheet1$]";
oleda = new OleDbDataAdapter(cmd);
oleda.Fill(ds); //<<<ERROR
An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code
Additional information: No value given for one or more required parameters.
Upvotes: 0
Views: 9498
Reputation: 4101
I've seen this before. Make sure your spreadsheet name is correct (if you're off by one character it won't work), your column names are correct, and your path is valid.
Wrap your data access in a Try...catch...finally block and you can probably get more error data.
Upvotes: 4