如何使用XML更新我的SQL数据库?

时间:2022-06-12 02:26:43

I have the following XML file:

我有以下XML文件:

<?xml version="1.0" encoding="utf-8"?>
<Patients>
  <Patient EMail="LeBron@James.com">
    <FirstName>LeBron</FirstName>
    <LastName>James</LastName>
  </Patient>
  <Patient EMail="Kobe@Bryant.com">
    <FirstName>Kobe</FirstName>
    <LastName>Bryant</LastName>
  </Patient>
  <Patient EMail="Allen@Iverson.com">
    <FirstName>Allen</FirstName>
    <LastName>Iverson</LastName>
  </Patient>
</Patients>

I want to store it in a SQL database which I have done successfully/

我想将它存储在我成功完成的SQL数据库中/

I then added some more data to the same XML File:

然后我在同一个XML文件中添加了一些数据:

<?xml version="1.0" encoding="utf-8"?>
<Patients>
  <Patient EMail="LeBron@James.com">
    <FirstName>LeBron</FirstName>
    <LastName>James</LastName>
  </Patient>
  <Patient EMail="Kobe@Bryant.com">
    <FirstName>Kobe</FirstName>
    <LastName>Bryant</LastName>
  </Patient>
  <Patient EMail="Allen@Iverson.com">
    <FirstName>Allen</FirstName>
    <LastName>Iverson</LastName>
  </Patient>
  <!-- New data starts here -->
  <Patient EMail="trtr@Iverson.com">
    <FirstName>tr</FirstName>
    <LastName>rson</LastName>
  </Patient>
  <Patient EMail="wewn@Iverson.com">
    <FirstName>Awerwren</FirstName>
    <LastName>Iveww</LastName>
  </Patient>
</Patients>

But it does not update in SQL database at runtime.....

但它在运行时没有在SQL数据库中更新.....

What am I doing wrong?

我究竟做错了什么?

2 个解决方案

#1


1  

Based on what you've posted, I'm guessing that perhaps there's a primary or unique key on the Patient table's FirstName and LastName columns, and the second time you try to insert data into the database this constraint is causing the inserts to fail.

根据您发布的内容,我猜测在Patient表的FirstName和LastName列上可能存在主键或唯一键,第二次尝试将数据插入数据库时​​,此约束导致插入失败。

Just a guess. Post more information and perhaps we can narrow it down a bit for you.

只是一个猜测。发布更多信息,也许我们可以为您缩小范围。

Share and enjoy.

分享和享受。

#2


0  

Delete the previous database. Create a new database with the new XML.

删除以前的数据库。使用新XML创建新数据库。

#1


1  

Based on what you've posted, I'm guessing that perhaps there's a primary or unique key on the Patient table's FirstName and LastName columns, and the second time you try to insert data into the database this constraint is causing the inserts to fail.

根据您发布的内容,我猜测在Patient表的FirstName和LastName列上可能存在主键或唯一键,第二次尝试将数据插入数据库时​​,此约束导致插入失败。

Just a guess. Post more information and perhaps we can narrow it down a bit for you.

只是一个猜测。发布更多信息,也许我们可以为您缩小范围。

Share and enjoy.

分享和享受。

#2


0  

Delete the previous database. Create a new database with the new XML.

删除以前的数据库。使用新XML创建新数据库。