I have three tables like below and one company can have multiple locations
Company - Id, Name ...
Locations - Id, City, State, Country ..
CompanyLocation, Id, CompanyId, LocationId
With below code company and location tables are getting updated, but the associated / junction table is not getting updated
// Create the SqlBulkCopy object.
using (var bulkCopy = new SqlBulkCopy(connection))
{
bulkCopy.DestinationTableName = TargetTable;
// Write from the source to the destination.
bulkCopy.WriteToServer(sourceTable);
}
Any help please?
Each SqlBulkCopy object is linked to one SQL table specified by the SqlBulkCopy.DestinationTableName Property, as showed in your code. Hence, a solution to update your three tables would be to instantiate three SqlBulkCopy objects, one for each table.