Click here to Skip to main content
15,887,931 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a xml file
named

data.xml
data in this file like...

XML
<countryData>
   <Country>
      <CName>AMERICAN SAMOA</CName>
      <CCode>AS</CCode>
   </Country>
   <Country>
      <CName>ANDORRA</CName>
      <CCode>AD</CCode>
   </Country>
   <Country>
      <CName>ANGOLA</CName>
      <CCode>AO</CCode>
   </Country>
   <Country>
</countryData>


now i want to insert that data in table

Table Defination like..

Id int
CName varchar(20)
CCode nchar(2)

then how can i import xml data to Table.....

plese help...

thnx
Posted

You can use ADO.NET DataSet ReadXml method. Here is MSDN example. DataSet.ReadXml[^]
 
Share this answer
 
 
Share this answer
 
That depends on how you want to import it; via code or SSIS.

For SSIS you may want to look at this http://blogs.msdn.com/b/mattm/archive/2007/12/11/using-xml-source.aspx[^]

For code there is nothing special. Parse the xml and insert.

If you give a little more detail maybe we can give you a more specific answer
 
Share this answer
 
v2
Comments
PKriyshnA 28-Jan-12 9:21am    
simply i have a data in xml file but i want to use that data in project as a sql server database

so i want to import xml data in sql server 2008 database table

DATA IN XML IS:
<countrydata>
<country>
<cname>AMERICAN SAMOA
<ccode>AS

<country>
<cname>ANDORRA
<ccode>AD

<country>
<cname>ANGOLA
<ccode>AO

<country>


and DATA IN TABLE SHOULD BE:

ID CName CCode
1 AMERICAN SAMOA AS
2 ANDORRA AD
3 ANGOLA AO
[no name] 28-Jan-12 10:03am    
Restating your question doesn't help to clarify anything.

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