Click here to Skip to main content
11,721,289 members (82,677 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML SQL-Server
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
Comments
ThePhantomUpvoter at 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 at 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
good
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.

Cheers,

Richard Rogers
http://www.RichardRogers.ca/[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 279
2 Mika Wendelius 170
3 F-ES Sitecore 150
4 cyycoish 70
0 Sergey Alexandrovich Kryukov 2,209
1 OriginalGriff 969
2 F-ES Sitecore 660
3 Maciej Los 609
4 Richard MacCutchan 560


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2015
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