2016-03-31 9 views
0

Ich möchte eine XML-Datei zu einer SQL Server-Tabelle zuordnen.XML-Mapping zu SQL-Server

Das ist, was ich bisher getan habe:

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(); 
} 

Der obige Code die Datenbankspalten ist. Ich möchte die XML-Datei laden und die Tags in die Spalten einfügen. Das Problem ist, dass ich nicht weiß, wie man die XML-Tags in die Datenbankspalten übersetzt. Kann mir jemand helfen?

+0

"_bums" "Seamen" (゜ - ゜) –

+0

Welche Sprache tun Sie dies in, btw? Ich nehme C# an? Sie möchten möglicherweise mit diesem (und Entitätsrahmen) markieren. –

+0

@G_H Seemann ist der Tisch –

Antwort

0

Dies ist nicht der gesamte Code, sollte aber helfen:

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

+0

Danke. Welche Verbindung meinen Sie in "// Verbindung hier erstellen"? –

+0

Was meinst du mit Datatable in Datenbank speichern? Ich möchte XML in der Datenbank speichern. Wie kann ich die XML-Tags in Datenbankspalten übersetzen? –