Hasibul Kamel

Hasibul Kamel

  • NA
  • 44
  • 4.2k

insert csv base on line

Sep 9 2020 1:27 AM
Hi, need help, how to insert into the database based on the last row in CSV. for example, I have 500 lines, all 500 lines already insert into the database. How to do if the row change to the 501 lines and the insert start from line 501. I want to replace it from delete, to insert from line 501. Help me please
  1. if (LWT > 0)  
  2. {  
  3.     Console.WriteLine("There are no changes in lastWriteTime CSV file");  
  4.     var del1 = "delete from result";  
  5.     var cmd11 = new NpgsqlCommand(del1, conn);  
  6.     cmd11.ExecuteNonQuery();  
  7. }  
  8. else  
  9. {  
  10.     Console.WriteLine("There are changes lastWriteTime in CSV file");  
  11.     var lf2 = "insert into listfile(filename)values(@filename)";  
  12.     var cmd3 = new NpgsqlCommand(lf2, conn);  
  13.     cmd3.Parameters.AddWithValue("filename", Convert.ToString(file));  
  14.     string filename = cmd3.Parameters["@filename"].Value.ToString();  
  15.     Console.WriteLine("Record inserted successfully. filename = " + file);  
  16. }  

Answers (1)