I use SqlBulkCopy to bulk insert some records from one table into another table. The query uses SqlDataReader to retrieve data. The only difference that matters (in addition to the column order that is processed in the mappings) between the tables is that the destination table has a date column to which the current date should be added. This date is not in the source table. How can I add this to the current process, which works fine minus?
The current working code is as follows:
SqlCommand cmd = new SqlCommand("SELECT * from dbo.source", cn); SqlDataReader rdr = cmd.ExecuteReader(); using (SqlBulkCopy copy = new SqlBulkCopy(cn)) { copy.ColumnMappings.Add(0, 0); copy.ColumnMappings.Add(1, 2); copy.ColumnMappings.Add(3, 3); copy.ColumnMappings.Add(2, 4); copy.ColumnMappings.Add(5, 5); copy.ColumnMappings.Add(14, 6); copy.DestinationTableName = "destination"; copy.WriteToServer(rdr); }
The database is an SQL ENT.
source share