scott oliver

scott oliver

  • NA
  • 82
  • 16.3k

Logic Error inserting values into sqlite from csv

Oct 11 2020 1:48 PM
Hello all. I am sure this has been asked before and I hope its an easy answer. I have some code that inserts information from a csv into sqlite. The csv has 9 colums but the table has 10 becuase I added a datetime column that needs to be added. I found some snips that seem to work, but I am not sure how to insert the date with it. I am trying not to have to break the csv into an array or something over complicated. below is the code and this is the web address of the instruction I found .
 
http://www.techbrothersit.com/2016/04/c-how-to-import-or-load-text-file-to.html
 
  1. while ((line = SourceFile.ReadLine()) != null)  
  2. {  
  3.     //skip the header row  
  4.     if (counter > 0)  
  5.     {  
  6.         //prepare insert query  
  7.         string query = "Insert into " + TableName +  
  8.                " Values ('" + line.Replace(filedelimiter, "','") + "')";  
  9.   
  10.         //execute sqlcommand to insert record  
  11.         SQLiteCommand myCommand = new SQLiteCommand(query, sqlConn);  
  12.         myCommand.ExecuteNonQuery();  
  13.     }  
  14.     counter++;  
  15. }  
 

Answers (3)