title: Data Entity error "An error occurred while updating the entries. See the inner exception for details."
body: <p>I'm new to Entity Framework, I already searched in google for this problem but I found nothing. I get the error </p>
  
  <blockquote>
    <p>An error occurred while updating the entries. See the inner exception for details.</p>
  </blockquote>
  
  <p>and when I checked the inner exception, I see this </p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'DOCNUM', table 'TCPIDBV2.dbo.tbl_200_Dailyreport'; column does not allow nulls. INSERT fails.</p>
  </blockquote>
  
  <p>But when I checked the records that I passed in to be saved in the database, there is a value in that object called 'DOCNUM'</p>
  
  <p>This is my code:</p>
  
  <pre><code>[Table("tbl_200_Dailyreport")]
  public class tbl_200_Dailyreport
  {
      [Key]
      [Required]
      public long DOCNUM {get; set;}
      public DateTime DAILYREPDATE {get; set;}
      public string SECTION {get; set;}
      public string REMARKS { get; set; }
      public int? OPERATIONTIME { get; set; }
      public int? PREPARATIONTIME { get; set; }
      public int? STANDBYTIME { get; set; }
      public int? MATERIALWAITING { get; set; }
      public int? ASSISTTIME { get; set; }
      public int? MAINTENANCETIME { get; set; }
      public int? CLEANINGTIME { get; set; }
      public bool? ISOVERTIME { get; set; }
      public bool? ISLOCKED { get; set; }
      public string SHIFT { get; set; }
      public int? PRODTIME { get; set; }
      public int? BREAKTIME { get; set; }
      public double? TOTALCOLOR { get; set; }
      public double? AVERAGECOLOR { get; set; }
  }
  </code></pre>
  
  <p>In getting a value of those above here is the code:</p>
  
  <pre><code>tbl_200_Dailyreport.DOCNUM = long.Parse(txtReferenceNo.Text);
  tbl_200_Dailyreport.PRODTIME = Convert.ToInt32(txtProduction.Text);
  tbl_200_Dailyreport.OPERATIONTIME = Convert.ToInt32(txtOperation.Text);
  tbl_200_Dailyreport.PREPARATIONTIME = Convert.ToInt32(txtPreparation.Text);
  tbl_200_Dailyreport.STANDBYTIME = Convert.ToInt32(txtStandby.Text);
  tbl_200_Dailyreport.MAINTENANCETIME = Convert.ToInt32(txtMaintenance.Text);
  tbl_200_Dailyreport.CLEANINGTIME = Convert.ToInt32(txtCleaning.Text);
  tbl_200_Dailyreport.MATERIALWAITING = Convert.ToInt32(txtMaterial.Text);
  tbl_200_Dailyreport.ASSISTTIME = Convert.ToInt32(txtAssist.Text);
  tbl_200_Dailyreport.BREAKTIME = Convert.ToInt32(txtOthers.Text);
  tbl_200_Dailyreport.DAILYREPDATE = dtpDailyReportDate.Value;
  tbl_200_Dailyreport.SHIFT = cboShift.SelectedValue.ToString();
  tbl_200_Dailyreport.ISOVERTIME = cbxOvertime.Checked;
  tbl_200_Dailyreport.ISLOCKED = false;
  tbl_200_Dailyreport.REMARKS = txtRemarks.Text;
  
  if (!String.IsNullOrEmpty(cboSecDepartment.Text)) 
  {
      tbl_200_Dailyreport.SECTION = cboSecDepartment.SelectedValue.ToString(); 
  }
  else
  {
      var section = "0";
      tbl_200_Dailyreport.SECTION = section;
  }
  </code></pre>
  
  <p>I allow all of the column to null except the PK called the 'DOCNUM', so in getting the value of 'DOCNUM', where the <code>txtreferenceno.Text</code> has a value that is equal to 1 . and passed it in DailyReportManager so here's the code:</p>
  
  <pre><code>public void Save(tbl_200_Dailyreport records)
  {
          try
          {
              this.db.tbl_200_Dailyreport.Add(records);
              this.db.SaveChanges();
          }
          catch (Exception ex)
          {
              throw ex;
          }
  }
  </code></pre>
  
  <p>and in getting the value of txtreferenceno.Text </p>
  
  <pre><code>var max = dailyreportmanager.FindAll().Max(x =&gt; (int?)x.DOCNUM) ?? 0;
  var addMax = max + 1;
  txtReferenceNo.Text = Convert.ToString(addMax);
  </code></pre>
  
  <p>so for the design of my database</p>
  
  <p>Allow me to post a screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/p9Paw.png" rel="nofollow noreferrer">Database Design</a></p>
  
  <p>When I checked the records, the 'DOCNUM' has a value equals to one, but why did I still get that error? Please help. A big thanks in advance.</p>