0

I am getting this error in Entity Framework while inserting. An error occurred while updating the entries.

Here is my code:

 public static void NewCustomer(string name,string address,string cnicno, string cellno,int productpurchasedid,string comments  )
 {
   using (CRMEntities context = new CRMEntities())
   { 
     Customer cs = new Customer() { name=name , address=address , cnicno = cnicno, cellno =cellno, productpurchasedid = productpurchasedid, comments=comments };
     context.Customers.Add(cs);
     context.SaveChanges();       //Error point
   }
 }
Ahmad Raza
  • 21
  • 3
  • 8
  • possible duplicate of [While saving some Client note, am getting this error " See 'EntityValidationErrors' property for more details"](http://stackoverflow.com/questions/22970085/while-saving-some-client-note-am-getting-this-error-see-entityvalidationerro) – Ehsan Sajjad Mar 16 '15 at 06:12
  • same question as this one:http://stackoverflow.com/questions/22970085/while-saving-some-client-note-am-getting-this-error-see-entityvalidationerro – Ehsan Sajjad Mar 16 '15 at 06:12
  • dear i tried that chunk of code but control is not going in catch block it trhows same exception – Ahmad Raza Mar 16 '15 at 06:25
  • hows that possible that it is not going in catch, how are you putting try catch? – Ehsan Sajjad Mar 16 '15 at 06:33
  • public static void NewEmployeeRole(string name, string desc) { try { using (CRMEntities context = new CRMEntities()) { EmployeeRole er = new EmployeeRole() { name = name, description = desc }; context.EmployeeRoles.Add(er); context.SaveChanges(); } } catch (DbEntityValidationException ex) { Console.WriteLine(message); } } } } – Ahmad Raza Mar 16 '15 at 06:48
  • Dear Ehsan.i have not uploaded the catch block code bcz it wasn't toolarge.....Do you know where i am making an error? – Ahmad Raza Mar 16 '15 at 06:55
  • you have to put try catch inside using – Ehsan Sajjad Mar 16 '15 at 06:57
  • i have putted it inside using block but same exception happening. – Ahmad Raza Mar 16 '15 at 07:09
  • In the exception dialog, click "View Detail" link and let us know what is the value for Inner Exception. – Dinesh Mar 16 '15 at 07:21
  • {"An error occurred while updating the entries. See the inner exception for details."} – Ahmad Raza Mar 16 '15 at 07:24
  • HI Dinesh,did you got any solution to this problem ? – Ahmad Raza Mar 16 '15 at 07:32

1 Answers1

0

Try checking if the ID column in database table has Identity set to true. If not, set it true.

Dinesh
  • 470
  • 4
  • 13