Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Comments
[no name] 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

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/[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900