Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got following exception when updating data from my database table
Exception : System.Reflection.TargetInvocationException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Here My Code

C#
private bool updateUser(UserCategoryModel userCategory)
 {
     using (var db = new EntityContext())
     {
         var currentUserCategory = db.UserCategories.FirstOrDefault(e => e.UserName == userCategory.UserName);
         db.Entry(currentUserCategory).State = EntityState.Modified;
         currentUserCategory.Catergories = userCategory.Catergories;
         db.SaveChanges();
         return true;
     }
     return false;
 }
Posted
Comments
Sergey Alexandrovich Kryukov 15-May-15 3:00am    
In what line?
—SA
Akalanka Kasun 15-May-15 4:00am    
var currentUserCategory = db.UserCategories.FirstOrDefault(e => e.UserName == userCategory.UserName);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900