将文件解析为数据表,如果说它们对于 csv 文件中的该行没有值,我如何允许它添加空值?
string fileName = @".csv";
using (StreamReader stream = new StreamReader(fileName))
{
DataTable dt = CsvParser.Parse(stream);
foreach (DataRow row in dt.Rows)
{
try
{
string lname = Convert.ToString(row[0].ToString().Trim());
string fname = Convert.ToString(row[1].ToString().Trim());
long s = Convert.ToInt64(row[2]);
string b = Convert.ToString(row[3]);
rec = row[0].ToString() + "," +
row[1].ToString() + "," +
row[2].ToString() + "," +
row[3].ToString() + ",";
write.WriteLine(rec);
}
}
}