I have a CSV file which has a delimiter of "|" to separate the fields.
I am using the code below to read the file and put it into a List
var reader = new StreamReader(File.OpenRead(openFileDialog1.FileName));
List<string> list1 = new List<string>();
List<string> list2 = new List<string>();
List<string> list3 = new List<string>();
List<string> list4 = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split('|');
list1.Add(values[0]);
list2.Add(values[1]);
list3.Add(values[2]);
list4.Add(values[3]);
}
then I'm gonna put it into a DataSet
DataSet ds = new DataSet();
ds.Tables.Add("barcode");
for (int i = 1; i < list1.Count; i++)
{
ds.Tables[0].Rows.Add(list1[i], list2[i], list3[i], list4[i]);
}
It's all good IF the data is like this
373|A0000006-04|EACH|2600003347225
373|A0000006-04|EACH|9556076004684
373|A0000006-04|EACH|9556076006374
373|A0000006-04|PK12|2600003347232
373|A0000006-04|PK12|9556076004691
However, some of the data might look like this
373|A0000029-01|PK12|1899886
6604250
373|A0000029-01|PK12|2652357563394
373|A0000030-01|EACH|2600001
539189
373|A0000030-01|EACH|8998866604284
As you can see, some of the data are using 2 lines. Is there any ways that I can read them as the same row instead of 2 different rows? Or do I have to put a delimiter such as a comma or semicolon in order to identify them as the same row?