Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 29.4k

How could I check if import this text file into DB or not ?

Jan 8 2020 3:52 AM
Hello everyone .
 
I have wrote a code which is reading Text Files and save them in a list after that import this list into DB so far it's fine the problem is i have until now 400 text fiels each text fiel has around 300000 until 500000 line and each time want to import a new text flel it will reinsert or reimport the text files which are already imported . that's meaing my data will be always duplicated.
so how could i check with C# code if this text files is already imported or exist in DB  ?!
 
here is some code to be more clear : 
  1. private static List<WebShopDataAccess> GetWebShopDataAccesses(string path)  
  2.         {  
  3.             List<WebShopDataAccess> elements = new List<WebShopDataAccess();  
  4.   
  5.             List<string> lines = File.ReadAllLines(path).ToList();  
  6. return elements;  
  7.   
  8. // here i am gettng the list back then import this list into DB during an extensions method with sqlbulk  
  9. }  
  10.   
  11.  private static void ImportToDB()  
  12.         {  
  13.             string CS =""  
  14.             using (SqlConnection connection = new SqlConnection(CS))  
  15.             {  
  16.                 SqlBulkCopy bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction, null);  
  17.   
  18.                 bulkCopy.DestinationTableName = "TestWebShop";  
  19.   
  20.                 connection.Open();  
  21.   
  22.                 bulkCopy.WriteToServer(GetListOfWebShop.AsDataTable());  
  23.             }  
  24.         }  
 
 
 

Answers (3)