Welcome! and rules
Joel on Software
Inserting UNIQUE data into SQL DB with...?
I would like to add new data to a SQL db. Specifically, Add new zip codes to existing zip code table. I import a text file of the most recent and up to date zip codes into a dataset. I next want to INSERT the New zips into the existing zip sql table, only inserting the newest zip codes ( Zip codes added since the last update).
Um, if you try to Insert data that would break the Primary Key Constraint the Database will reject it. Hence only new data would make it. What you do with the returned errors from the Insert is up to you.
Indeed. Or do away with the DataSet and DataAdpater and just rip through the text file using a StreamReader and issue SqlCommands to the database. Stick a try...catch around it to catch those that violate the unique/primary key.
Firing off commands and catching errors sounds pretty nasty.
Indeed. I think the majority of the time will be taken up inserting the data into the database in the first place. To do the bulk insert you could use good old BCP.exe.
Fog Creek Home