Disregard the header of a .csv file when importing into the database

1

I need at the time of reading a .csv file to disregard the header at the time of importing to the database how is it possible?

I'm using the following code:

linhaArquivo = arquivo.ReadLine(); 

campos = linhaArquivo.Split(new string[] { ";" }, 
    StringSplitOptions.None);

registro = dt.NewRow();
    
asked by anonymous 17.09.2014 / 19:53

1 answer

2

This code must be within a loop that iterates between the lines of the file.

Just ignore the first iteration by adding an if below linhaArquivo = arquivo.ReadLine() :

bool cabecalhoJaLido = false;

for ... // você não postou o código que mostra o loop.

    linhaArquivo = arquivo.ReadLine(); 

    if (!cabecalhoJaLido) {
        cabecalhoJaLido = true;
        continue;
    }

    campos = linhaArquivo.Split(new string[] { ";" }, 
        StringSplitOptions.None);
    
17.09.2014 / 20:15