如何使用带提交和回滚的CAML在sharepoint列表中插入主详细信息记录 [英] how to insert master details records in sharepoint list using CAML with commit and rollback

查看:74
本文介绍了如何使用带提交和回滚的CAML在sharepoint列表中插入主详细信息记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将主要详细信息记录插入2个列表(1个主要,2个详细信息)。我想确保是否成功插入完整数据以提交进程else回滚,就像我们在sql server中使用commit和rollback一样。


使用CAML提交和回滚的工作方式是什么查询


谢谢


解决方案


没有API来确保交易,你需​​要制作逻辑作为'交易'工作。


例如,在创建项目后,检查ID以确认其创建,并使用try catch来捕获异常,如果异常,则删除父项。

 using(var clientContext = new ClientContext(" http://) sp:12001 /"))
{
try
{
var web = clientContext.Web;
var oList = web.Lists.GetByTitle(" Cases");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem [" Title"] =" My New Item!" ;;
oListItem.Update();

clientContext.ExecuteQuery();
Console.WriteLine(oListItem.Id);
if(oListItem.Id> 0)
{
//要做,创建子项。
// try {}
// catch(){delete parent item}
}
}
catch(exception ex)
{

}
}


最诚挚的问候,


Lee


Hi,

I want to insert master details record into 2 lists (1 master ,2 details ) . I want to make sure if full data inserted successfully to commit the process else roll back , like we use commit and rollback in sql server.

what's the way to work like commit and rollback using CAML queries

Thanks

解决方案

Hi,

There is no API to ensure transaction, you need make the logic to work as ‘transaction’ .

For example, after an item created, check the ID to confirm its’ creation, and use try catch to catch the exception, if exception, delete parent item.

using (var clientContext = new ClientContext("http://sp:12001/"))
            {
                try
                {
                    var web = clientContext.Web;
                    var oList = web.Lists.GetByTitle("Cases");
                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    ListItem oListItem = oList.AddItem(itemCreateInfo);
                    oListItem["Title"] = "My New Item!";                    
                    oListItem.Update();

                    clientContext.ExecuteQuery();
                    Console.WriteLine(oListItem.Id);
                    if (oListItem.Id > 0)
                    {
                        //to do,create child item.
                        //try { }
                        //catch(){ delete parent item}
                    }
                }
                catch (Exception ex)
                {

                }
            }

Best Regards,

Lee


这篇关于如何使用带提交和回滚的CAML在sharepoint列表中插入主详细信息记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆