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

  • Thread starter Thread starter Ben_Omran
  • Start date Start date
B

Ben_Omran

Guest
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 :

private static List<WebShopDataAccess> GetWebShopDataAccesses(string path)
{
List<WebShopDataAccess> elements = new List<WebShopDataAccess();

List<string> lines = File.ReadAllLines(path).ToList();
return elements;

// here i am gettng the list back then import this list into DB during an extensions method with sqlbulk
}

private static void ImportToDB()
{
string CS =""
using (SqlConnection connection = new SqlConnection(CS))
{
SqlBulkCopy bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction, null);

bulkCopy.DestinationTableName = "TestWebShop";

connection.Open();

bulkCopy.WriteToServer(GetListOfWebShop.AsDataTable());
}
}




Continue reading...
 
Back
Top