我的 csv 文件包含 8 列和 300k 行。这是我的 csv 文件的示例“0195153448”;“古典神话”;“Mark PO Morford”;“2002”;“牛津大学出版社”;“ http://images。 amazon.com/images/P/0195153448.01.THUMBZZZ.jpg ";" http://images.amazon.com/images/P/0195153448.01.MZZZZZZZ.jpg ";" http://images.amazon.com/images/ P/0195153448.01.LZZZZZZZ.jpg “
0002005018”;“Clara Callan”;“Richard Bruce Wright”;“2001”;“HarperFlamingo Canada”;” http://images.amazon.com/images/P/0002005018.01.THUMBZZZ .jpg ";" http://images.amazon.com/images/P/0002005018.01.MZZZZZZZ.jpg ";"http://images.amazon.com/images/P/0002005018.01.LZZZZZZZ.jpg "
现在我有这个代码供阅读
string path = @"C:\Users\SEMRUK\Desktop\exceller\kitaplik.csv";
public DataTable GetDataTabletFromCSVFile(string PathFile)
{
DataTable csvData = new DataTable();
TextFieldParser csvReader = new TextFieldParser(PathFile);
csvReader.SetDelimiters(new string[] {";"});
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
csvData.Columns.Add(datecolumn);
}
string[] fieldData = csvReader.ReadFields();
while (!csvReader.EndOfData)
{
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
MessageBox.Show(fieldData[i]);
}
csvData.Rows.Add(fieldData);
}
return csvData;
}
这样我可以读取前 8 行。但是在那之后我什么都不能读取。它只读取第 8 行。我怎样才能告诉代码它也应该在选项卡之后读取。我尝试将 \t 添加到 setdelimiters 但没有不行。有什么建议吗?