[英]Is there a way to map all the empty fields inside .csv file as NULL using Microsoft.VisualBasic.FileIO's TextFieldParser
I am working on a C# console application.我正在开发一个 C# 控制台应用程序。 and I am reading a .csv file using Microsoft.VisualBasic.FileIO package.我正在使用 Microsoft.VisualBasic.FileIO 包读取 .csv 文件。 as follow:-如下:-
class Program
{
static void Main(string[] args)
{
Entities entities = new Entities();
TextFieldParser parser = new TextFieldParser(@"C:\My.csv");
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
string[] fields = parser.ReadFields();
Can I define to map any empty .csv cell as NULL?我可以定义将任何空的 .csv 单元格映射为 NULL 吗? For example, currently I can trim all the values doing specifying this:例如,目前我可以修剪所有指定此值的值:
parser.TrimWhiteSpace = true;
Can I set the parser to map any empty cell as Null
?我可以设置解析器将任何空单元格映射为Null
吗?
Thanks谢谢
as per @Hans answer No, turning empty strings into NULL is your job.根据@Hans 的回答不,将空字符串转换为 NULL 是您的工作。 – Hans Passant yesterday – 昨天汉斯·帕桑特
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.