我使用下面的代码来阅读我的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