Wednesday, May 28, 2014

An error occurred while updating the entries. See the inner exception for details.



If you are using EF then you may get the error. This error is not specify where the error exactly occur in your table. To specify the error use this code & use debugger to see the exact error message.


  try  
       {  
                 //Your code  
                     db = new FEDALIC_AGRI_DBEntities ();  
                     model.FarmerVillage = new Guid(village);  
                     model.FarmerThana = new Guid(thana);  
                     model.FarmerDistrict = new Guid(district);  
                     var _SET_FARMER_INFO = EMFermar.SetToModelObject(model);  
                     db.SET_FARMER_INFO.Add(_SET_FARMER_INFO);  
                     db.SaveChanges();  
       }  
       catch (DbUpdateException e)  
       {  
         var innerEx = e.InnerException;  
         while (innerEx.InnerException != null)  
           innerEx = innerEx.InnerException;  
         throw new Exception(innerEx.Message);  
       }  
       catch (DbEntityValidationException e)  
       {  
         var sb = new StringBuilder();  
         foreach (var entry in e.EntityValidationErrors)  
         {  
           foreach (var error in entry.ValidationErrors)  
           {  
             sb.AppendLine(string.Format("{0}-{1}-{2}",  
               entry.Entry.Entity,  
               error.PropertyName,  
               error.ErrorMessage  
               )  
             );  
           }  
         }  
         throw new Exception(sb.ToString());  
       }  



[NB: I got this exception because of duplicate primary key when I am going to insert in my table]
Thank you.

C# print file on LAN Printer

If you want to print any file on network printer then you can try with this code block // Change Default Printer System.Ma...