I have a little background in .NET, mostly self taught and I rarely have to ask for help, however here I am.
I have a script that analyses CSV files (KBCSV Lib) and updates a database with the values from these CSV files. I can get that to work fine using SQLBulkCopy. The problem I am having is when the values already exist in the database, SQLBulkCopy will just append. After a few google searches, the solution seems to reside in populating datatables; One with values from the CSV, One with values from the Database - And then merging the two together.
I have done this, and the datatables populate and merge. The issue I am having is the data from the CSV gets appended, it does not update the original values in the datatable storing the database values.
I have tried changing preserveChanges to both true and false. No avail.
Dim firstdatatable As DataTable = New DataTable
Dim Seconddatatable As DataTable = New DataTable
Dim finaldatatable As DataTable = New DataTable
Dim DbProdList = EntityToDatatable(fillqry, econtext)
Dim TempProdList = EntityToDatatable(fillfromtemp, econtext)
Firstdatatable = DbProdList.Copy()
Seconddatatable = TempProdList.Copy()
firstdatatable.Merge(Seconddatatable, False, MissingSchemaAction.Add
User Name, Password, Full Name, Restriction list name, Banned word checking, Allow attachments, Template, Group, Mailbox size, Calendar, SyncML
psmith01,CLASS3B,Pauly Smith 1,YEAR2,1,N,ADVANCED,STAFF,1,Y,Y
mrsjohns,SNHOJ,Mrs R Johns,UNRESTRICTED,-1,Y,ADVANCED,STAFF,2,Y,N
psmith02,CLASS588,Peter Smith 2, UKSCHOOLS,0,N,ADVANCED,STAFF,10,Y,Y
Just a quick note: When I am importing the CSV, I have templates specified (I have coded logic where the user selects what column in the CSV corresponds to what column in the database) and before the CSV is SQLBulkCopied, I map the columns.
Using bcp As SqlBulkCopy = New SqlBulkCopy(connStr)
bcp.DestinationTableName = "dbo.tempinventoryimport"
If categorybool = True Then
If subcategorybool = True Then
No matter how I try and merge the two datatables, the information appends to the end (Add's new rows with the same information). Some help would be muchly appreciated :)