Hello:
My question is that with the code below, I am unable to update the database.
I get the following exception, as it runs through each field:
The field ____ must be a string or array type with a maximum length of ____.
As I understand things with my db, we are within the constraints. I added trim because it appeared there may be some spaces in there to truncate.
My question is that with the code below, I am unable to update the database.
I get the following exception, as it runs through each field:
The field ____ must be a string or array type with a maximum length of ____.
As I understand things with my db, we are within the constraints. I added trim because it appeared there may be some spaces in there to truncate.
C#:
// Get Database Records
string IDVal = dgvJobs.CurrentRow.Cells[0].Value.ToString();
int IDVal_int = Int32.Parse(IDVal);
// Update database Records
using (var db_Jobs = new ResourcePlanningEntities())
{
var getJobRecord = db_Jobs.Jobs.FirstOrDefault(a => a.ID == IDVal_int);
getJobRecord.Customer = cboCustomer.ToString().Trim();
getJobRecord.City = cboCity.ToString().Trim();
getJobRecord.State = cboState.ToString().Trim();
getJobRecord.Country = txtCountry.ToString().Trim();
getJobRecord.EngineerProjectLead = cboEngineerProjectLead.ToString().Trim();
getJobRecord.ProjectManager = cboProjectManager.ToString().Trim();
getJobRecord.ShipDate = Convert.ToDateTime(txtShipDate.Text);
try
{
db_Jobs.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException ex)
{
foreach (var entityValidationErrors in ex.EntityValidationErrors)
{
foreach (var validationError in entityValidationErrors.ValidationErrors)
{
MessageBox.Show("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
}
}
}
}