1

我的数据库字段是

Id which is primary key and auto increment
imagename varchar(max)
imagepath varchar(max)
isdeleted bit

现在我正在使用 openxml 进行批量插入。它在 imagename 和 imagepath 列中插入空值。这是我的存储过程:

alter PROCEDURE PB_Insertgallery   
  @XmlString nText
AS
BEGIN    
    SET NOCOUNT ON;
DECLARE @XMLDocPointer INT  

    EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @XmlString     
   INSERT INTO tb_gallery
   (imagename, imagepath)    
   SELECT imagename,imagepath
   FROM OPENXML(@XMLDocPointer,'/NewDataSet/Table1',2)    
    WITH  (imagename VARCHAR(max),  --'@ImageName',     
         imagepath VARCHAR(max)     --'@ImagePath'
          )   
   EXEC sp_xml_removedocument @XMLDocPointer 
END
GO

xml字符串是:

<NewDataSet>
     <Table1>
          <Imagename>Chrysanthemum.jpg</Imagename>
          <Imagepath>/prop_images/temp/Chrysanthemum.jpg</Imagepath>
     </Table1>
</NewDataSet>

请帮帮我;为什么我在插入期间得到空值?

4

1 回答 1

1

这是由于区分大小写,SQL 中的 imagename、imagepath 是小写的,而在 ntext 中有一些大写。

alter PROCEDURE test   
  @XmlString nText,
  @Propertyid Varchar(100),
  @Builderid Varchar(100)
AS
BEGIN    
    SET NOCOUNT ON;
DECLARE @XMLDocPointer INT  

    EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @XmlString     
   INSERT INTO tb_gallery
   (Imagename, Imagepath, Propertyid, Builderid)    
   SELECT Imagename,Imagepath, @Propertyid, @Builderid
   FROM OPENXML(@XMLDocPointer,'/NewDataSet/Table1',2)    
    WITH  (Imagename VARCHAR(max),  --'@ImageName',     
         Imagepath VARCHAR(max)     --'@ImagePath'
          )   
   EXEC sp_xml_removedocument @XMLDocPointer 
END
GO
于 2013-02-05T20:06:30.330 回答