我使用下面的代碼來閱讀我的csv文件:閱讀從CSV文件中的字母數字字符在C#
public DataTable ParseCSV(string path)
{
if (!File.Exists(path))
return null;
string full = Path.GetFullPath(path);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
//create the "database" connection string
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=\"" + dir + "\\\";"
+ "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";
//create the database query
string query = "SELECT * FROM " + file;
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
//create an OleDbDataAdapter to execute the query
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
//fill the DataTable
dAdapter.Fill(dTable);
dAdapter.Dispose();
return dTable;
}
但上面並沒有讀取CSV文件中的字母數字值。它只讀我數字或阿爾法。
我需要做什麼修復來讀取字母數字值?請建議。
我試過了,但是它仍然是同樣的結果 – Prasad 2010-04-13 08:16:58
奇怪,我在做一些工作,並使用大致相同的代碼,但使用不同的連接字符串作爲逗號分隔文件 - Provider = Microsoft.Jet.OLEDB.4.0; Data Source = DirName; Extended Properties ='text; HDR = Yes; FMT =分隔」 – anonymous 2010-04-13 08:44:38