I have a DataSet
populated from Excel Sheet. I wanted to use SQLBulk Copy to Insert Records in Lead_Hdr
table where LeadId
is PK.
Well, is it right? Do the column names exist on both sides?
To be honest, I've never bothered with mappings. I like to keep things simple - I tend to have a staging table that looks like the input on the server, then I SqlBulkCopy
into the staging table, and finally run a stored procedure to move the table from the staging table into the actual table; advantages:
As a final thought - if you are dealing with bulk data, you can get better throughput using IDataReader
(since this is a streaming API, where-as DataTable
is a buffered API). For example, I tend to hook CSV imports up using CsvReader as the source for a SqlBulkCopy. Alternatively, I have written shims around XmlReader
to present each first-level element as a row in an IDataReader
- very fast.