正在读取 Excel 文件 - 没有为一个或多个必需参数提供值

Reading Excel file - No value given for one or more required parameters

更新:

更新正确的路径后,我收到了新的错误提示 "External table is not in the expected format."

我不确定这段代码有什么问题,我正在尝试阅读 excel sheet,下面是我的代码并收到以下错误。

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.

我以前见过这个。确保您的电子表格名称是正确的(如果您偏离一个字符,它将不起作用),您的列名是正确的,并且您的路径是有效的。

将您的数据访问包装在 Try...catch...finally 块中,您可能会获得更多错误数据。