With SQLBulkCopy, junction tables are not updated.

c# sqlbulkcopy

Question

I have three tables like the ones shown, and a single business might have many locations.

Company - Id, Name ...

Locations - Id, City, State, Country ..

CompanyLocation, Id, CompanyId, LocationId

The associated/junction table is not updated with the following code, but the company and location tables are.

// Create the SqlBulkCopy object.                
using (var bulkCopy = new SqlBulkCopy(connection))
{
    bulkCopy.DestinationTableName = TargetTable;
    // Write from the source to the destination.
    bulkCopy.WriteToServer(sourceTable);
}

Can you please help?

1
0
6/21/2012 1:01:35 AM

Popular Answer

According to your code, each Obj SqlBulkCopy is connected to a certain SQL table that the DestinationTableName Property in SqlBulkCopy has defined. Therefore, creating three instances of type objects using SqlBulkCopy, one for each table, would be a way to updating your three tables.

0
6/21/2012 1:24:42 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow