这是我第一次使用 XML 将数据插入表中。我将前端的数据(所有 Datagridview 行)保存到 xml 文件中,并将其发送到数据库以插入表 SD_ShippingDetails。下面是查询用于读取 XML 数据和保存数据。从查询中可以看到,我正在删除相关的 ShippingID 详细信息并再次插入。(从 SD_ShippingDetails WHERE ShippingID=@ShippingID 删除)。我们可以通过获取更新 SD_ShippingDetails 中的现有行吗?来自 XML 的数据。如果是,请帮我查询。
CREATE PROCEDURE SD_Insert_ShippingDetails
@PBMXML as varchar(Max),
@ShippingID as INT
AS
BEGIn
declare @i int
exec sp_xml_preparedocument @i output,@PBMXML
DELETE FROM SD_ShippingDetails WHERE ShippingID=@ShippingID
INSERT INTO SD_ShippingDetails(ShippingID,Weight,Height,TotalBoxes,Price)
SELECT ShippingID,Weight,Height,TotalBoxes,Price FROM OPENXML(@i,'Root/ShippingBox',2)
WITH (
ShippingID int,Weight varchar(20),Height varchar(20),TotalBoxes varchar(20),Price numeric(18,2))
exec sp_xml_removedocument @i
END
谢谢。