Guest User

Guest User

  • Tech Writer
  • 77
  • 13.9k

read csv file and save it to database

Jul 20 2020 2:05 AM
hi, wanna ask
 
how to read from CSV file and save it to database row by row.
 
In the code below, it will open the CSV file and read the data row by row.
 
 foreach (string path in Directory.EnumerateFiles(@"C:\ipub\root", "*.csv"))
 {
   string[] lines = System.IO.File.ReadAllLines(path);
   foreach (string line in lines)
 {
   Console.WriteLine(line);
 }
 }
 
how to change this code, so that after it opens the CSV file and then read row by row after that save it to database.
 
Or there have another way to do it 
 
thank you
I using visual studio 2019, c#
 

Answers (2)