Over a million developers have joined DZone.

Export Data And Reimport Using Xml

·
// 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
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}