Click here to Skip to main content
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 4: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 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2014
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