数据库批量更新,添加!有关XML的操作
得到一个需要处理的XMl
private string GetSaveItem()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<menuCollection/>");
foreach (TreeNode node in trvAccessRight.CheckedNodes)
{
if (node != trvAccessRight.Nodes[0])
{
XmlElement content = xmlDoc.CreateElement("menuItem");
content.SetAttribute("menuID", node.Value);
xmlDoc.DocumentElement.AppendChild(content);
}
}
return xmlDoc.OuterXml;
}
将以上的获得的XMl字符串当参数传入存储过程中,
存储如下写
ALTER PROCEDURE [dbo].[usp_UserGroup_SetRight]
(@GroupID INT ,@ChangedBy VARCHAR(50) ,@MenuXml XML)
AS
BEGIN
--SET XACT_ABORT ON
BEGIN TRY
BEGIN TRANSACTION
--delete
DELETE
from tbl_SysUserGroupRight
WHERE GroupId = @GroupID
--insert
INSERT INTO tbl_SysUserGroupRight
(
GroupId
,MenuID
,ChangedBy
,ChangedOn
)
SELECT @GroupID
,menuList.row.value(N'@menuID' ,'VARCHAR(50)') AS MenuID
,@ChangedBy
,GETDATE()
from @MenuXml.nodes('/menuCollection/menuItem') AS menuList(row)
COMMIT TRANSACTION
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
RETURN 0
END CATCH
更新可以借鉴上面的添加操作,
相关文档:
//pugxml.h
///////////////////////////////////////////////////////////////////////////////
//
// Pug XML Parser - Version 1.0002
// --------------------------------------------------------
// Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
// Released into the Public Domain. Use at yo ......
//这是添加
private void button1_Click(object sender, EventArgs e)
{
string s = "Persist Security Info=False;Integrated Security=SSPI;database=IIntegration;server=(local)";
&n ......
If XML data in the table is less than 32K for each record, then you can directly unload the data as char. If XML data exceeds 32K for some records, then you have to unload the common data and the XML data separately. First, create a template for unloading XML into a PDS: TEMPLATE LOBFRV DSN 'AAA. ......
*
sql xml 入门:
--by jinjazz
--http://blog.csdn.net/jinjazz
1、xml: 能认识元素、属性和值
2、xpath: 寻址语言,类似wind ......