IErrorInfo.GetDescription失败时带有E_FAIL(0x80004005).System.Data而数据适配器Fill()
我正试图从CSV文件中获取数据,通过使用fill()方法我得到了一个exceptionidk为什么会出现,请查看代码并提出乐观的答案。如果参数“s”没有任何空格意味着它有效精细。 如果它有空间意味着如何克服它,不建议临时重命名和所有。
/// /// Import Function For CSV Delimeted File /// /// File Name private DataTable Import4csv(string s) { string file = Path.GetFileName(s); string dir = Path.GetDirectoryName(s); string sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=\"" + dir + "\\\";" + "Extended Properties=\"text;HDR=YES;FMT=Delimited\""; try { var objConn = new OleDbConnection(sConnection); objConn.Open(); var ds = new DataSet(); var da = new OleDbDataAdapter("SELECT * FROM " + file, sConnection); da.Fill(ds); // getting exception on this line. objConn.Close(); return ds.Tables[0]; } catch (Exception ex) { Trace.WriteLine(ex.Message + ex.Source); return null; } }
var da = new OleDbDataAdapter("SELECT * FROM `" + file + "`", sConnection);
靠近波浪键
我遇到了同样的问题,但能够通过将可疑字放在方括号中来克服它。
就我而言,这是我在“Where”条件中使用的字段名称,即;
select * from tblDetail where [Section] = 'Operations'
在我的情况下,用*
替换查询中的整个字段名称解决了问题。