解析CSV时我遇到了一个奇怪的问题,一个空列x的行正在从列x的前一行返回一个值。代码如下。
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='text;HDR=Yes;FMT=Delimited';";
using (OleDbConnection cn = new OleDbConnection(connectionString)
{
cn.Open();
using (OleDbCommand cmd = cn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM [" + fileName + ".csv]";
cmd.CommandType = CommandType.Text;
using (OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
foreach (DbDataRecord record in reader)
{
string value = !record.IsDBNull(9) ? record.GetValue(9).ToString() : string.Empty;
etc