我試圖從CSV文件獲取數據,通過填寫()方法,我有一個例外IDK的爲什麼它出現時,請查看代碼並建議樂觀的答案。如果參數「s」沒有任何空格意味着它可以正常工作。如果有空間意味着如何克服這一點,不建議臨時重命名和所有。IErrorInfo.GetDescription失敗,E_FAIL(0x80004005的).System.Data而數據適配器填充()
/// <summary>
/// Import Function For CSV Delimeted File
/// </summary>
/// <param name="s">File Name</param>
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;
}
}
它不工作。 –
固定它,你需要之前有空格的文件名後使用'字符 – shobhonk