0

I want to map a xml file to a SQL Server table.

This is what I've done so far:

XmlTextReader reader = new XmlTextReader("navetout.xml");
XmlNodeType type;

while (reader.Read())
{
    type = reader.NodeType;

    if(type == XmlNodeType.Element)
    {
    }
}

//using Entity framework
static void writeToDatabase()
{
    BumsEntities _bums = new BumsEntities();

    _bums.Seamen.Add(new Seamen
                     {
                        PersonalIdentityNumber = "",
                        ReferedCivicRegistrationNumber = "",
                        UnregistrationReason = "",
                        UnregistrationDate = "",
                        MessageComputerComputer = "",
                        GivenNameNumber = "",
                        FirstName = "",
                        MiddleName = "",
                        LastName = "",
                        NotifyName = "",
                        NationalRegistrationDate = "",
                        NationalRegistrationCountyCode = "",
                        NationalRegistrationMunicipalityCode = "",
                        NationalRegistrationCoAddress = "",
                        NationalRegistrationDistributionAddress1 = "",
                        NationalRegistrationDistributionAddress2 = "",
                        NationalRegistrationPostCode = "",
                        NationalRegistrationCity = "",
                        NationalRegistrationNotifyDistributionAddress = "",
                        NationalRegistrationNotifyPostCode = "",
                        NationalRegistrationNotifyCity = "",
                        ForeignDistrubtionAddress1 = "",
                        ForeignDistrubtionAddress2 = "",
                        ForeignDistrubtionAddress3 = "",
                        ForeignDistrubtionCountry = "",
                        ForeignDate = "",
                        BirthCountyCode = "",
                        BirthParish = "",
                     });

    _bums.SaveChanges();
}

The code above is the database columns. What I want to be able to do is to load the xml file and insert the tags into the columns. The problem is that I don't know how to "translate" the xml tags to the database columns.. Can anyone help me out?

Simon.S
  • 107
  • 1
  • 1
  • 9

1 Answers1

0

This is not the entire code, however should help :

XmlTextReader reader = new XmlTextReader("navetout.xml");
DataSet ds = new DataSet("XML Data");
ds.ReadXml(reader);

// Create Database Connection here

foreach(DataTable dt in ds.Tables){

//save datatable to database - You can use SqlBulkCopy

}

Saving DataTable to database

Community
  • 1
  • 1
Ravi Singh
  • 2,042
  • 13
  • 29
  • Thanks. What connection do you mean in "//Create connection here"? – Simon.S Mar 31 '16 at 09:46
  • What do you mean with saving datatable to database? I want to save XML to database. How I can translate the XML-tags to database columns? – Simon.S Mar 31 '16 at 10:40