c# - Update / Insert to SQL table using datatable with column mappings -
i'm wanting bulk copy of data 1 database another. needs dynamic enough when users of source database create new fields, there minimal changes @ destination end(my end!).
i've done using sqlbulkcopy function, using column mappings set in seperate table, if new created need create new field , set mapping (no code or stored procedure changes):
foreach (var mapping in columnmapping) { var split = mapping.split(new[] { ',' }); sbc.columnmappings.add(split.first(), split.last()); } try { sbc.writetoserver(sourcedatatable); }
however, requirements have changed.
need keep more data, sourced elsewhere, in other columns in table means can't truncate whole table , write sqlbulkcopy. now, need able insert new records or update relevant fields current records, still dynamic enough won't need code changes if users create new fields.
does have ideas?
comment on original question mdisibio - looks sql merge statement have been answer.
Comments
Post a Comment