Click here to Skip to main content
13,152,454 members (36,972 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am trying to copy data from xml to my database table but i get one approach as best i.e:

using SqlBulkCopy

but i am not able to achieve my task. I need to copy data from xml to sql database avoiding duplication's in table. and if same data exists dont copy it , if new insert it and updated then make updations in table.

Any help is appreciated.
Posted 25-May-13 3:43am
ThePhantomUpvoter 25-May-13 9:48am
Delete the data in the database before you do your copy and then then won't be any duplicate data.
Maciej Los 25-May-13 14:13pm
Please, be more specific and provide more details. We can't read in your mind and we can't help you without knowing the structure of xml and table. Use "Improve question" widget to update question.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If this is something you would like to automate, and to implement in C#, you could:
- Use XmlTextReader to process the XML
- Write a stored procedure in MS SQL Server that stores the data coming from XML, with some logic for duplicate data

If this is a one time only process, you could:
- Import the XML data into Excel, and save it as a .csv
- Use SSIS/DTS to import the .csv data into a new table in your database
- Write a query that selects only the non-duplicates from the new table, and inserts them into the table you want.

I could do either approach if you need additional help.


Richard Rogers[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170924.2 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100