问题是在数据表中读取时,长数被转换为指数。例如,数字 1215313371140020130606144217 转换为 1.21531337114002E+27。
我的代码:
public static DataTable GetCSVRows(string path, bool IsFirstRowHeader)
{
string header = "Yes";
string sql = string.Empty;
string pathOnly = string.Empty;
string fileName = string.Empty;
DataTable dataTable = new DataTable();
try
{
pathOnly = Path.GetDirectoryName(path);
fileName = Path.GetFileName(path);
sql = @"SELECT * FROM [" + fileName + "]";
if (IsFirstRowHeader)
{
header = "Yes";
}
using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathOnly + ";Extended Properties=\"Text;HDR=" + header + "\""))
{
using (OleDbCommand command = new OleDbCommand(sql, connection))
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
{
dataTable = new DataTable();
adapter.Fill(dataTable);
}
}
}
}
}