TAN WhoAMI

TAN WhoAMI

  • NA
  • 291
  • 0

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

Jun 6 2013 9:07 PM
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)