1

I am pretty new to coding ADO.Net/entity framework stuff. I am trying to follow "Microsoft ADO.NET Entity Framework Step by Step", Microsoft Press Mueller. I'm using VS 2012 with EF6 installed.

Start a new project, and adding an new Empty ADO.NET Entity Data Model. It's pretty simple, a few scalars and one Enumeration called UserFavorites. Then add a data source > Object > Drilling down to my UserFavorites object and finishing. I change toe UserFavorites object on the data source tab to detail view ( and a couple other changes like combo box and label on the others). Then drag the UserFavorites object to the form. It creates a Binding source and binding navigator all as it should. After enabling the save button and entering the code below it runs great and gets the records from the database that can be scrolled between. The problem is when I click the plus to add a record, fill it in, and click save, I get validation errors. on the Hide Copy Code UserFavoritesContext.SaveChanges(); line. The first error is "Exception:Thrown: "Value of '1/1/0001 12:00:00 AM' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'." (System.ArgumentOutOfRangeException)"

There is a date picker on the form, and it's filled out correctly. If I remove that item from my model I get errors on the next item in the model. For some reason it's not pulling the data filled in on the form and trying to use defaults (or null).

I can't find anyone else with this problem online, so I guess I am missing something silly. I followed the book exactly ( and can't find a help forum for the book). I hope this is clear enough for someone to offer some guidance.

Images of Form and Data Source,Model,Error, and zip of project are at https://www.dropbox.com/sh/z6yhvbp1uk7bobm/AADa7fnS82PzwNLlPrycnCYza?dl=0

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserFavoritesEF6
{
    public partial class Form1 : Form
    {
        // Define the context used to access the database.
        UserFavoritesModelContainer UserFavoritesContext;

<pre>
    public Form1()
    {
        InitializeComponent();

        // Initialize the database context.
        UserFavoritesContext = new UserFavoritesModelContainer();

        // Query the database for the records you want.
        var dbQuery =
           UserFavoritesContext.UserFavorites.Where(id =&gt; id.UserId &gt;= 0).ToArray();
    }

    private void userFavoritesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
        UserFavoritesContext.SaveChanges();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

        // Assign a local copy of the queried records to the
        // binding source.
        userFavoritesBindingSource.DataSource =
           UserFavoritesContext.UserFavorites.Local;

        // Fill the Favorite Colors list with acceptable colors and
        // choose a default.
        favoriteColorComboBox.DataSource = Enum.GetValues(typeof(ColorNames));
        favoriteColorComboBox.SelectedItem = ColorNames.Red;
    }

}

}
user1212738
  • 21
  • 1
  • 1
  • 2
  • Refer to the following as it may lead you to a working solution. http://stackoverflow.com/questions/15824070/datepicker-value-set-error-binding-to-datasource or the following, http://stackoverflow.com/questions/468045/error-sqldatetime-overflow-must-be-between-1-1-1753-120000-am-and-12-31-999 – James Shaw Apr 07 '15 at 03:07

0 Answers0