Results 1 to 2 of 2

Thread: [RESOLVED] Unable to Import an Exported DataSet

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,987

    Resolved [RESOLVED] Unable to Import an Exported DataSet

    I am using the following to export a DataSet:
    Code:
    Using saveFileDialogExport = New SaveFileDialog()
        saveFileDialogExport.Filter = "XML Files|*.xml|All Files|*.*"
        saveFileDialogExport.Title = "Export Database"
        saveFileDialogExport.DefaultExt = "xml"
        saveFileDialogExport.AddExtension = True
        saveFileDialogExport.FileName = "database.xml"
    
        If (saveFileDialogExport.ShowDialog() = DialogResult.OK) Then
            Dim filePath = saveFileDialogExport.FileName
            My.Application.Database.WriteXml(filePath, XmlWriteMode.WriteSchema)
        End If
    End Using
    I am then using the following to import it back:
    Code:
    Private Sub ButtonImportData_Click(sender As Object, e As EventArgs) Handles ButtonImportData.Click
        Using openFileDialogImport = New OpenFileDialog()
            openFileDialogImport.Filter = "XML Files|*.xml|All Files|*.*"
            openFileDialogImport.Title = "Import Database"
            openFileDialogImport.DefaultExt = "xml"
            openFileDialogImport.AddExtension = True
    
            If (openFileDialogImport.ShowDialog() = DialogResult.OK) Then
                Dim filePath = openFileDialogImport.FileName
                My.Application.Database.Clear()
                My.Application.Database.ReadXml(filePath, XmlReadMode.ReadSchema)
                My.Application.Database.AcceptChanges()
                RaiseEvent ImportingData(Me, EventArgs.Empty)
            End If
        End Using
    End Sub
    But I'm getting this error:
    'Invalid 'Key' node inside constraint named: FK_Redacted_RedactedId.'
    How the constraint be invalid if I'm importing what I immediately exported?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,987

    Re: Unable to Import an Exported DataSet

    Long story short, I'm an idiot. Changing the XmlReadMode to IgnoreSchema resolved the issue.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width