1

我正在做一些大学工作并接近尾声,但是我一直坚持尝试将我的 XML 数据导入我的数据库

执行时传递的消息是"0 row(s) affected"如果有人可以帮助我,我将非常感激。

下面是我的查询和 XML 数据。

USE Daniel
GO

INSERT INTO Customer (customerid, custname, custaddress1, custaddress2, custaddress3, custpostcode, custemail, custtelno, custcomment, custupdatedate)    
    SELECT X.customer.query('customerid').value('.', 'INT'),  
           X.customer.query('custname').value('.', 'NVARCHAR(50)'),  
           X.customer.query('custaddress1').value('.', 'NVARCHAR(100)'),
           X.customer.query('custaddress2').value('.', 'NVARCHAR(100)'),
           X.customer.query('custpostcod3').value('.', 'NVARCHAR(100)'),
           X.customer.query('custpostcode').value('.', 'NVARCHAR(10)'),  
           X.customer.query('custemail').value('.', 'NVARCHAR(50)'),  
           X.customer.query('custtelno').value('.', 'NVARCHAR(25)'),  
           X.customer.query('custcomment').value('.', 'NVARCHAR(100)'),
           X.customer.query('custupdatedate').value('.', 'DATETIME')


    FROM (
    SELECT CAST(x AS XML)
    FROM OPENROWSET(
        BULK 'N:\University Work\Year 2\Database\Resit July-13\Resit JuneJuly\XML and XSD with Tests\customerXML.xml',

        SINGLE_BLOB) AS T(x)
        ) AS T(x)
        CROSS APPLY X.nodes('/customer/row') AS X(customer);

<?xml version="1.0" encoding="utf-8"?>
<!--
Document CustomerXML.xml
Author: Daniel McGurk
-->

<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="CustomerXSD.xsd">
    <row>
    <customerid>42</customerid>
  <custname>James Woodrow</custname>
  <custaddress1>80 Ashby Road</custaddress1>
  <custaddress2>Kingstanding</custaddress2>
  <custaddress3>Birmingham</custaddress3>
  <custpostcode>B20 7TH</custpostcode>
  <custemail>JamesWoodrow@hotmail.co.uk</custemail>
  <custtelno>07821455616</custtelno>
  <custcomment>Good value for money</custcomment>
  <custupdatedate>2013-05-30T09:00:00</custupdatedate>
    </row>
    <row>   
    <customerid>16</customerid>
    <custname>Eric Newman</custname>
    <custaddress1>12 Barnes Close</custaddress1>
    <custaddress2>Perry Barr</custaddress2>
    <custaddress3>Birmingham</custaddress3>
    <custpostcode>B20 3HT</custpostcode>
    <custemail>mrnewwman@hotmail.co.uk</custemail>
    <custtelno>07821453616</custtelno>
    <custcomment>Cheap prices</custcomment>
    <custupdatedate>2013-06-30T09:00:00</custupdatedate>
    </row>
    <row>
    <customerid>33</customerid>
    <custname>Chris Gann</custname>
    <custaddress1>5 Westcott</custaddress1>
    <custaddress2>Rubery</custaddress2>
    <custaddress3>Birmingham</custaddress3>
    <custpostcode>B44 5BM</custpostcode>
    <custemail>chrisgann@hotmail.co.uk</custemail>
    <custtelno>07913456219</custtelno>
    <custcomment>Quality assurance always gaurenteed</custcomment>
    <custupdatedate>2012-03-12T09:00:00</custupdatedate>
    </row>
</Customer>
4

0 回答 0