4
Answers

Ado.net entity frmawork error getting while saveChanges()

P Narasimha

P Narasimha

11y
13.7k
1
Hi All,

Please help me anybody on this.

I am getting below error while save data into database.

I am using Code firtst entity Framework.

error is this. error on Updating record "An error occurred while updating the entries. See the inner exception for details.

Model is 
       [Key]
        public int UserId { get; set; }
 public User SaveUser(User user)
        {
            try
            {
                if (user.UserId == 0)
                {
                   
                    var UserId = objSequenceHelper.GetNextValue(DomainModels.Enumerations.Sequences.S_SECURITY_USER);
                    //StoreGeneratedPattern.Identity.ToString();
                    user.UserId = UserId;
                    db.Users.Add(user);
                }
                else
                    db.Entry(user).State = System.Data.EntityState.Modified;
                db.SaveChanges();
                return user;
            }
}

while saving geting above error .
Answers (4)
0
Alexandru Lazar

Alexandru Lazar

NA 62 0 14y

Sorry for the C# code; I hadn't noticed what forum this was on, but I'm sure you can translate all that in VB.NET
0
Rob Cro

Rob Cro

NA 3 2.6k 14y
Is this forum for C# or Visual Basic?
0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 14y
Be sure to also look at the recommended articles listed in the right side of the forum windows.
0
Alexandru Lazar

Alexandru Lazar

NA 62 0 14y
Here is a very ugly implementation (I don't have the time to make it performant), but you can get the idea of how it works.

private bool panelIsGrabbed = false;
private int xDistance, yDistance;

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
   xDistance = panel1.Location.X - e.X;
   yDistance = panel1.Location.Y - e.Y;
   panelIsGrabbed =
true;
}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
   if (panelIsGrabbed)
   {
      panel1.Location =
new Point(e.X + xDistance, e.Y + yDistance);
   }
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
   panelIsGrabbed =
false;
}