Import XML into access db
-
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
-
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