Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Import XML into access db

Import XML into access db

Scheduled Pinned Locked Moved Visual Basic
databasecssxmlannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tessers
    wrote on last edited by
    #1

    Hi all, I use the following code to import a XML file into an Access database: Dim ds As New DataSet Dim streamRead As New System.IO.FileStream(strFileName, System.IO.FileMode.Open) ds.ReadXml(streamRead) streamRead.Close() If ds.Tables.Count > 0 Then strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbname objConnection = New OleDbConnection(strConnection) objConnection.Open() objAdapter = New OleDbDataAdapter() objAdapter.ContinueUpdateOnError = True Dim cb As New OleDbCommandBuilder(objAdapter) For intI = 0 To ds.Tables.Count - 1 If ds.Tables(intI).Rows.Count > 0 Then cb.RefreshSchema() objAdapter.SelectCommand = New OleDbCommand("SELECT * FROM [" + ds.Tables(intI).TableName + "] ", objConnection) objAdapter.Fill(ds, ds.Tables(intI).TableName.ToString) objAdapter.UpdateCommand = cb.GetUpdateCommand() objAdapter.Update(ds, ds.Tables(intI).TableName.ToString) End If Next objConnection.Close() End If The import works fine, but when a next XML file is imported with less records, the database don't get updated and the 'old' records remain in the database. Simply delete the 'old' records is fine by me. Can somebody point me to the right direction. With kind regards, Jurgen

    E 1 Reply Last reply
    0
    • T tessers

      Hi all, I use the following code to import a XML file into an Access database: Dim ds As New DataSet Dim streamRead As New System.IO.FileStream(strFileName, System.IO.FileMode.Open) ds.ReadXml(streamRead) streamRead.Close() If ds.Tables.Count > 0 Then strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbname objConnection = New OleDbConnection(strConnection) objConnection.Open() objAdapter = New OleDbDataAdapter() objAdapter.ContinueUpdateOnError = True Dim cb As New OleDbCommandBuilder(objAdapter) For intI = 0 To ds.Tables.Count - 1 If ds.Tables(intI).Rows.Count > 0 Then cb.RefreshSchema() objAdapter.SelectCommand = New OleDbCommand("SELECT * FROM [" + ds.Tables(intI).TableName + "] ", objConnection) objAdapter.Fill(ds, ds.Tables(intI).TableName.ToString) objAdapter.UpdateCommand = cb.GetUpdateCommand() objAdapter.Update(ds, ds.Tables(intI).TableName.ToString) End If Next objConnection.Close() End If The import works fine, but when a next XML file is imported with less records, the database don't get updated and the 'old' records remain in the database. Simply delete the 'old' records is fine by me. Can somebody point me to the right direction. With kind regards, Jurgen

      E Offline
      E Offline
      Ebube
      wrote on last edited by
      #2

      explicitly set the update command

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups