使用open xml在批量更新期间插入空值

时间:2013-02-05 19:08:53

标签: asp.net sql-server sql-server-2008

我的数据库字段是

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>

请帮帮我;为什么我在插入过程中得到空值?

1 个答案:

答案 0 :(得分: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