Decimal causing issues when not physcially typed in by the user

c# asp.net webforms

28 просмотра

1 ответ

I am having a issue with entitys and saving I am wanting to update a value of a record so i am doing the following.

I use the following in other oens but its not working here some reason to save the record it says that the key already exists.

_dal.portalEntities.Entry(_custInfo).State = System.Data.Entity.EntityState.Modified;
_dal.portalEntities.SaveChanges();
_dal.portalEntities.Entry(_custInfo).Reload();

Here is my main routine

tblPortalUser _users; 
_users = _dal.GetUserRecordByEmail(_myuser.EmailAddress.ToLower());
//password is the same warn the user as current 
 if (PasswordHash.ValidatePassword(password.Text, _users.password) == true)
{    
    lblerror.Text = "Password choose a password you have not used before";
    }else
 lblerror.Text = "Current Password is invalid.";
            // if password is the same as the confirm password then proceed if not warn the user
 if (password.Text == confirmpass.Text)
 {
   _users.password = PasswordHash.HashPassword(password.Text);
  _dal.portalEntities.SaveChanges();
 //lets send out the verification codes for the email and sms
   _notifications.sendNotification(new Guid(portalbl.BLConstants.resetPasswordEmail), _custInfo.firstName + " " + _custInfo.lastName, "", _custInfo.email.ToLower(), "", "", portalbl.BLConstants.portalNotifications.Email, "");
 Response.Redirect(@"~\myaccount\logout.aspx", false);
 }

GetUserRecordByEmail

public tblPortalUser GetUserRecordByEmail(string Email)
    {
        try
        {
            tblPortalUser _user;

            _user = (from _users in _dal.portalEntities.tblPortalUsers
                     where _users.EmailAddress.ToLower() == Email
                     select _users).FirstOrDefault();


            return _user;
        }
        catch (Exception ex)

        {
            string inner = string.Empty;
            if (ex.InnerException != null)
            {
                inner = ex.InnerException.ToString();
            }
            return null;
        }
    }

Edit 1 The exception is showing here sorry i do not no how to include an image without a link when score is below ten

/content/images/no-img.jpg

Автор: rogue39nin Источник Размещён: 08.11.2019 11:29

Ответы (1)


0 плюса

From the screen shot, the exception is clear, you need first Detach the user and attach it again, and it will work

look to this article:Attaching and Detaching Objects

Автор: Tarek Abo ELkheir Размещён: 20.08.2016 05:06
Вопросы из категории :
32x32