DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Export Data And Reimport Using Xml

12.05.2008
| 7319 views |
  • submit to reddit
        // Outputs a database into XML then reimports

    Friend Sub OutPutXML()
        Try
            Dim dsBranch As DataSet = GetDataset("SELECT * FROM Branch")
            dsBranch.WriteXml("c:\branches.xml")
            dsBranch = Nothing
            Dim dsOrg As DataSet = GetDataset("SELECT * FROM Organisation")
            dsOrg.WriteXml("c:\organisation.xml")
            dsOrg = Nothing
        Catch Ex As Exception
            ThrowError(Ex)
        End Try
    End Sub

The to reimport

    Friend Sub LoadInitialData()
        Dim ds As New DataSet
        Dim su As New SharedUtil
        Try

            ds = New DataSet
            Dim dbad1 As New SqlDataAdapter("SELECT * FROM Organisation", GetConnectionString)
            Dim cb1 As SqlCommandBuilder = New SqlCommandBuilder(dbad1)
            dbad1.Fill(ds)
            ds.ReadXml(su.XMLtoDataset("organisation.xml"))
            dbad1.Update(ds, "Table")
            dbad1 = Nothing
            ds = Nothing