1
Answer

Add Record to table, but System.Data.Entity.Validation error

TAN WhoAMI

TAN WhoAMI

11y
1.9k
1
I am using the EF 5.0 to Add Record to a table named Customer of the Northwind database, but always got this System.Data.Entity.Validation.DbEntityValidationException.Can anyone help?

Code as below:

  private void Add_btn_Click(object sender, RoutedEventArgs e)
        {
            using (NorthwindEntities context = new NorthwindEntities())
            {
                Customer cust = new Customer()
                {
                    CompanyName = "DotNetCurry",
                    ContactName = "Suprotim Agarwal"
                };
                context.Customers.Add(cust);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    MessageBox.Show(ex.ToString());
                }             
            }           
        }
Answers (1)