更新:
更新正确的路径后,我收到的新错误显示"External table is not in the expected format."
我不确定这段代码有什么问题,我正在尝试阅读excel表,下面是我的代码,并收到以下错误。
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); //<<<ERRORSystem.Data.dll中出现“System.Data.OleDb.OleDbException”类型的异常,但未在用户代码中处理
Additional information: No value given for one or more required parameters.
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); //<<<ERRORAn 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块中包装您的数据访问,您可能会获得更多的错误数据。
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.
更多推荐
发布评论