Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 101.5k

How Do I Update Record Using Ef

Nov 14 2015 6:02 AM
i want to update multiple column value using Ef of one record but its does not give any error and there is no updating too
Hide Expand Copy Code
Entities ef1 = new Entities();              
     int id1 = SafeConvert.ToInt16(ddlRollNo.SelectedValue);   
                var emp1 = (from em in ef1.ModifiedNames where em.Id == id select em).FirstOrDefault();   
                var Emp1 =(from em in ef1.Employees where em.Id == emp.BeltNo select em).FirstOrDefault(); 
                   CTP.HRMS.WebApp.EF.Employee Emp = new EF.Employee();                    Emp.UserName = MyUser.UserName;     
               Emp.EntryDate = DateTime.Now;   
                 Emp.Id =Emp.Id ;  
                  Emp.CtrNo = txtCtrNo.Text;     
               Emp.Rank_Id = SafeConvert.ToByte(ddlRank.SelectedValue);  
                  Emp.Name = txtName.Text;  
                  Emp.Fathername = txtFatherName.Text;    
                Emp.Address = txtAddress.Text; 
                   Emp.Height = txtHeight.Text;   
                 Emp.Chest = txtChest.Text;    
                Emp.Caste = txtCaste.Text;     
               Emp.DistinguishMark = txtDistinguishMark.Text;  
                  Emp.Cnic = txtCnic.Text;  
                  Emp.SeniorityNo = SafeConvert.ToInt16(txtSeniorityNo.Text);    
                Emp.DateOfBirth = SafeConvert.ToDateTime(txtDateOfBirth.Text);
                    Emp.DateOfEnrollment = SafeConvert.ToDateTime(txtDateOfEnrollment.Text); 
                   Emp.Education_Id = SafeConvert.ToByte(ddlEducation.SelectedValue);    
                Emp.Province_Id = SafeConvert.ToByte(ddlProvince.SelectedValue);     
               Emp.District_Id = SafeConvert.ToByte(ddlDistrict.SelectedValue);       
             Emp.EntryTestMarks = SafeConvert.ToDecimal(txtEntryTestMarks.Text);   
                 Emp.CourceTestMarks = SafeConvert.ToDecimal(txtCourceTestMarks.Text);    
                Emp.CellNo = txtCellNo.Text;    
                Emp.MartialStatus_Id = SafeConvert.ToByte(ddlMartialStatus.SelectedValue); 
                   Emp.OtherQualification = txtOtherQualification.Text;     
               Emp.IsEligibalForRouteDuty = txtIsEligibalForRouteDuty.Checked;      
              Emp.ImgBody = (Emp.ImgBody == null) ? new byte[0] : EmpImg.ImgBody;      
              //Image saving code                    Byte[] imgByte = null;   
                 if (txtEpPicture.HasFile && txtEpPicture.PostedFile != null)   
                 {    
                    //To create a PostedFile    
                    HttpPostedFile File = txtEpPicture.PostedFile;    
                    //Create byte Array with file len                        imgByte = new Byte[File.ContentLength];   
                     //force the control to load data in array                        File.InputStream.Read(imgByte, 0, File.ContentLength); 
                       Emp.ImgBody = imgByte;   
                 }                    ef1.Employees.Attach(ef1.Employees.Single(x => x.Id == Emp1.Id));      
                ef1.SaveChanges();      
              MsgLitteral.ShowNotificationInline("Employee Has Been Updated", true); 

how to update multiple field using EF?? PLZ