gpt4 book ai didi

通过 VBScript 的 SQLXMLBulkLoad

转载 作者:数据小太阳 更新时间:2023-10-29 02:32:15 26 4
gpt4 key购买 nike

我正在运行以下代码:

    Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad")
objBL.ConnectionString = "provider=SQLOLEDB.1;data

source=mySQLServer;database=myDB;uid=SA;pwd=myPword"
objBL.ErrorLogFile = "c:\error.log"
objBL.Execute "c:\xml\schema.xml", "c:\xml\addresses.xml"
Set objBL = Nothing

我正在尝试将一个相当大的 XML 文件加载到 SQL 表中,但是我收到错误消息“无法将 NULL 值插入列‘LocID’,表‘myDB.dbo.myTable’;列不允许空值。INSERT 失败。”

“LocID”是我的主键和身份字段。有没有办法阻止它向此列插入 NULL,因为我只是加载数据,而不是移动数据,而且我在 XML 文件中没有 ID 字段?

最佳答案

在 objBL.Execute 之前添加这个

objBL.KeepIdentity = False

来自 MSDN 文章 SQL Server XML Bulk Load Object Model (SQLXML 4.0) (强调我的)

KeepIdentity

Specifies how to deal with the values for an Identity typecolumn in the source file. This is aBoolean property. When the property isset to TRUE, XML Bulk Load assigns thevalues that are specified in thesource file to the identity column.When the property is set to FALSE, the bulk-load operation ignores the identity-column values that are specified in the source. In this case,SQL Server assigns a value to theidentity column.

If the Bulk Load involves a columnthat is a foreign key referring to anidentity column in which SQLServer-generated values are stored,Bulk Load appropriately propagatesthese identity values to the foreignkey column.

The value of this property applies toall columns involved in the bulk load.The default value is TRUE.

关于通过 VBScript 的 SQLXMLBulkLoad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5749907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com