LINQ TO SQL ::数据更新问题 [英] LINQ TO SQL :: Data Update Problem

查看:60
本文介绍了LINQ TO SQL ::数据更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目(使用3层方法),其中我正在使用LINQ TO SQL ... 我想更新用户...

i am developing a project (using 3-tier approach) in which i am using LINQ TO SQL... i want to update user...

但是我面临一些问题.它不会给我任何错误,但也不会更新用户详细信息

but i am facing some problem. it does not give me any error but also do not update the user detail

这是程序顺序;

在UpdateProfile.aspx中

in UpdateProfile.aspx

String currentUser = Session["BMUser"].ToString();

            String displayName = txtDisplayName.Text;
            String username = currentUser;
            String emailAddress = txtEmailAddress.Text;
            String secretQuestion = txtSecretQuestion.Text;
            String secretAnswer = txtSecretAnswer.Text;

                if (UserManager.UpdateProfile(username, displayName, emailAddress, secretQuestion, secretAnswer))
                {
                    lblStatus.Text = "Profile Updated";
                }
                else
                    lblStatus.Text = "Unable to Update Profile"; 

UserManager是BLL类

the UserManager is BLL class

public class UserManager
{           
        public static bool UpdateProfile(String username, String displayName, String emailAddress, String secretQuestion, String secretAnswer)
        {

        // This method will return BM_User (BM_User in entity class generated by LINQ TO SQL)       

            BM_User user = UserCatalog.GetUserByName(username);
            if (user != null)
            {
                user.DisplayName = displayName;
                user.EmailAddress = emailAddress;
                user.SecretQuestion = secretQuestion;
                user.SecretAnswer = secretAnswer;               

                if (UserManagerDAO.UpdateUser(user, false))
                {
                    //HttpContext.Current.Session["BMUser"] = userToUpdate;
                    return true;
                }
                else
                    return false;
            }
            else
                return false;
        }
}

最后是UserManagerDAO

and finally UserManagerDAO

public class UserManagerDAO
{
   public static bool UpdateUser(BM_User user, bool changeLoginDateTime)
        {
            BugManDataContext db = new BugManDataContext();            

            if (changeLoginDateTime == true)
                user.LastLoginDate = DateTime.Now;            
            db.SubmitChanges();
            return true;
        }
}

在此之后,当我获得此更新用户的详细信息时.它显示了我以前的细节.意味着它不会用新的细节来更新用户的详细信息...

after this when i get the detail of this updated user. it shows me previous detail. mean it is not updating the user's detail with new one...

请解决这个问题

推荐答案

在UpdateUser方法中,您声明了一个新的DataContext,因此未附加BM_User参数,这就是SubmitChanges方法什么都不做的原因.

In your UpdateUser method you are declaring a new DataContext, so the BM_User paramter is not attached to it and that's why the SubmitChanges method does nothing.

这篇关于LINQ TO SQL ::数据更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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