?
Solved

Updating an Access database using an XML document ...

Posted on 2005-03-23
5
Medium Priority
?
172 Views
Last Modified: 2010-04-16
Hi

I am relatively new to XML so the question should be easy enough.

Given an XML document that has all the tags defined for a corresponding table in Access, how do you UPDATE the database with the data contained in the XML document.

I have been able to ADD a row (for when the primary key data doesn't exist in the database), but how do you UPDATE????

Cheers

sr
0
Comment
Question by:srigby22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 10

Expert Comment

by:makerp
ID: 13610717
you would need to have a specific column that was the ID of the column to update, for example

<items>
  <item>
    <name>new name</name>
    <id>123</id>
  </items>
 <item>
    <name>new name again</name>
    <id>321</id>
  </items>
</items>

you would then need to use XPath to select your nodes and exeute SQL based on the value, for example

sql_string = "UPDATE table SET name = '" + name + "' WHERE id = " + id

you could get cleaver and make this generic, for example

<table>my_table_name</table>
<items>
  <item>
    <name>new name</name>
    <id id='yes'>123</id>
  </items>
 <item>
    <name>new name again</name>
    <id id='yes'>321</id>
  </items>
</items>

now you could build the query dynamically and use the fact that the ID entry is marked as id to know this is the where clause. the node names would be the same as the column names in the database

-P
0
 
LVL 10

Accepted Solution

by:
makerp earned 400 total points
ID: 13610732
XPathNavigator _navigator = (new XPathDocument(new FileStream("myfile.xml",FileMode.Open))).CreateNavigator();
XPathNodeIterator _iterator = _navigator.Select("/items/item");
while(_iterator.MoveNext())
{
   // use the _iterators members to ge the node values and build the sql query
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question