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.

Sunday, May 25, 2014

Kendo UI web Grid how to set default null values to a grid when adding new row

In your Kendo UI web grid model binding just use '?' allow null in your model class property. Which property you want to use in your grid as nullable.
Model:
  [Key]  
     public System.Guid? CompanyId { get; set; }  
     public System.String CompanyName { get; set; }  
     public System.String CompanyAddress { get; set; }  

Kendo Grid :

  .Columns(columns =>  
   {  
     columns.Bound(p => p.CompanyId).Hidden();  
     columns.Bound(p => p.CompanyName).Width(200);  
     columns.Bound(p => p.CompanyAddress).Width(300);  
     columns.Command(command => { command.Edit(); command.Destroy();}).Width(172);  
   })  

UI



Sunday, May 11, 2014

how to pass the multiple values in session ASP.NET


Set Value in session
  // Set value in one UI in session  
       string empIdList = GetSelectedIDofGrid();  
       var paramObjects = new Dictionary<string, object>  
       {  
         {"paramEmployeeXmlstr", empIdList},  
         {"paramFactoryId", ddlFactoryName.SelectedValue}  
       };  
       Session["paramPayroll_RPT014_Staff"] = paramObjects;  

Get value from session

 // Get Value in another UI From session  
     private string _paramEmployeeXmlstr = String.Empty;  
     private string _paramFactoryId = String.Empty;  
     var paramObjects = Session["paramPayroll_RPT014_Staff"] as Dictionary<string, object>;  
       if (paramObjects != null)  
       {  
         _paramEmployeeXmlstr = (string)paramObjects["paramEmployeeXmlstr"];  
         _paramFactoryId = (string)paramObjects["paramFactoryId"];  
       }  


Thursday, May 8, 2014

sql row value wise count

Query:

 SELECT   COUNT(CASE WHEN DayStatusID = 1 THEN 1 END) AS A,  
             COUNT(CASE WHEN DayStatusID = 7 THEN 1 END) AS B,  
             COUNT(CASE WHEN DayStatusID = 3 THEN 1 END) AS C  
 from Payroll_tblYearMonthDayEntry  

Result:


SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...