SPList没有更新?

发布于 2024-12-16 12:26:34 字数 2699 浏览 0 评论 0原文

我正在尝试更新用户的 UserInformationList 。它正在正确执行 SPListItem.Update() 但更新未反映在列表中。我不明白我在哪里做错了。我在这里附上我的代码。

private bool SyncingProcess(SqlDataReader d, SPList UserInfoList)
    {
        bool result =false;
        try
        {            //-->
            SPListItem UILUser = null;
            // Build a query.
            SPQuery query = new SPQuery();
            query.Query = string.Concat( "<Where><Eq>","<FieldRef Name='Name'/>",
                "<Value Type='Text'>" +(d.IsDBNull(accountIDPOS) == false
                     ? d.GetString(accountIDPOS)
                     : "information not found") + "</Value>",
                "</Eq></Where>");

            query.ViewFields = string.Concat("<FieldRef Name='FirstName' />","<FieldRef Name='LastName' />",
                "<FieldRef Name='Email' />","<FieldRef Name='FullName' />","<FieldRef Name='Title' />",
                "<FieldRef Name='JobTitle' />");

            SPListItemCollection userInfoListitems = UserInfoList.GetItems(query);
            if (userInfoListitems != null && userInfoListitems.Count > 0)
            {
                UILUser = userInfoListitems[0];
                SPUser user1 = UILUser.Web.EnsureUser("aspnetsqlmembershipprovider:" + d.GetString(accountIDPOS));                  
                if (UILUser != null)
                {  
                    UILUser["FirstName"] = (d.IsDBNull(FIRSTNAMEPOS) == false ? d.GetString(FIRSTNAMEPOS) : "");                           
                    UILUser["LastName"] = (d.IsDBNull(LASTNAMEPOS) == false ? d.GetString(LASTNAMEPOS) : "");
                    UILUser["Title"] = (d.IsDBNull(FULLNAMEPOS) == false ? d.GetString(FULLNAMEPOS) : "");
                    UILUser["EMail"] = (d.IsDBNull(EMAIL_ADDRESSPOS) == false? d.GetString(EMAIL_ADDRESSPOS): "");
                    UILUser["JobTitle"] = (d.IsDBNull(TITLEPOS) == false ? d.GetString(TITLEPOS) : "");
                    UILUser.Update();;
                    UserInfoList.Update();   
                }
                result =true;
            }
            else
            {
                tw.WriteLine("User not found in the " + UserInfoList.ParentWeb.Title.ToString() + " Site " +
                             (d.IsDBNull(FIRSTNAMEPOS) == false
                                  ? d.GetString(FIRSTNAMEPOS) + "; " + d.GetString(accountIDPOS)
                                  : "information not found"));
                tw.Flush();
            }

        }
        catch (Exception)
        {
            result =false;
        }
        return result;
    }
}

}

I am trying to update UserInformationList for the user. It is executing SPListItem.Update() properly but update was not reflect in the list. I don't understand where I am doing mistake. I attaching my code here.

private bool SyncingProcess(SqlDataReader d, SPList UserInfoList)
    {
        bool result =false;
        try
        {            //-->
            SPListItem UILUser = null;
            // Build a query.
            SPQuery query = new SPQuery();
            query.Query = string.Concat( "<Where><Eq>","<FieldRef Name='Name'/>",
                "<Value Type='Text'>" +(d.IsDBNull(accountIDPOS) == false
                     ? d.GetString(accountIDPOS)
                     : "information not found") + "</Value>",
                "</Eq></Where>");

            query.ViewFields = string.Concat("<FieldRef Name='FirstName' />","<FieldRef Name='LastName' />",
                "<FieldRef Name='Email' />","<FieldRef Name='FullName' />","<FieldRef Name='Title' />",
                "<FieldRef Name='JobTitle' />");

            SPListItemCollection userInfoListitems = UserInfoList.GetItems(query);
            if (userInfoListitems != null && userInfoListitems.Count > 0)
            {
                UILUser = userInfoListitems[0];
                SPUser user1 = UILUser.Web.EnsureUser("aspnetsqlmembershipprovider:" + d.GetString(accountIDPOS));                  
                if (UILUser != null)
                {  
                    UILUser["FirstName"] = (d.IsDBNull(FIRSTNAMEPOS) == false ? d.GetString(FIRSTNAMEPOS) : "");                           
                    UILUser["LastName"] = (d.IsDBNull(LASTNAMEPOS) == false ? d.GetString(LASTNAMEPOS) : "");
                    UILUser["Title"] = (d.IsDBNull(FULLNAMEPOS) == false ? d.GetString(FULLNAMEPOS) : "");
                    UILUser["EMail"] = (d.IsDBNull(EMAIL_ADDRESSPOS) == false? d.GetString(EMAIL_ADDRESSPOS): "");
                    UILUser["JobTitle"] = (d.IsDBNull(TITLEPOS) == false ? d.GetString(TITLEPOS) : "");
                    UILUser.Update();;
                    UserInfoList.Update();   
                }
                result =true;
            }
            else
            {
                tw.WriteLine("User not found in the " + UserInfoList.ParentWeb.Title.ToString() + " Site " +
                             (d.IsDBNull(FIRSTNAMEPOS) == false
                                  ? d.GetString(FIRSTNAMEPOS) + "; " + d.GetString(accountIDPOS)
                                  : "information not found"));
                tw.Flush();
            }

        }
        catch (Exception)
        {
            result =false;
        }
        return result;
    }
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昇り龍 2024-12-23 12:26:34

您可能需要调用UserInfoList.ParentWeb.Update()

You might want to call UserInfoList.ParentWeb.Update()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文