SqlDateTime Overflow exception after Profile_OnMigrateAnonymous
<p>In my web application on visual web developer 2010 express, i'm using profiles to store user credentials and the items in his/her current shopping cart (by using a custom class). 
I wanted to give the customers the possibility of starting adding items to their shopping carts before they login, so i wrote some code to handle the Profile_OnMigrateAnonymous event. </p>

<p>Here it is :</p>

<pre><code>       void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs e)
{
    ProfileCommon anonymousProfile = Profile.GetProfile(e.AnonymousID);
    if (anonymousProfile.Orders.SCart != null)
    {
        if (Profile.Orders.SCart == null)
            Profile.Orders.SCart = new Cart();

        Profile.Orders.SCart.Items.AddRange(anonymousProfile.Orders.SCart.Items);
        Profile.Save();

        anonymousProfile.Orders.SCart = null;
        anonymousProfile.Save();
    }

    ProfileManager.DeleteProfile(e.AnonymousID);
    AnonymousIdentificationModule.ClearAnonymousIdentifier();
}
</code></pre>

<p>My web.config settings concerning Profiles usage, are listed below:</p>

<pre><code>    &lt;anonymousIdentification enabled="true"/&gt;

&lt;profile automaticSaveEnabled="false"&gt;
  &lt;properties&gt;
    &lt;group name="Location"&gt;
      &lt;add name="Address"/&gt;
      &lt;add name="Latitude"/&gt;
      &lt;add name="Longitude"/&gt;
      &lt;add name="PhoneNumber"/&gt;
      &lt;add name="Other"/&gt;
    &lt;/group&gt;
    &lt;group name="Orders"&gt;
      &lt;add name="SCart" serializeAs="Binary" type="Cart" allowAnonymous="true"/&gt;
    &lt;/group&gt;
  &lt;/properties&gt;
&lt;/profile&gt;
</code></pre>

<p>There's no problem until VS runs this code :</p>

<pre><code>    private void InsertOrder()
{
    // Setting up queries parameters
    string insertSQL = "";

    insertSQL += "INSERT INTO Orders (";
    insertSQL += "UserName, DateCreated, LastUpdate, Description, PaymentType, Delivery, Total) ";
    insertSQL += "VALUES (@UserName, @DateCreated, @LastUpdate, @Description, @PaymentType, @Delivery, @Total)";

    SqlCommand cmd0 = new SqlCommand(insertSQL, connection);

    cmd0.Parameters.AddWithValue("@UserName", Profile.UserName.ToString());
    cmd0.Parameters.AddWithValue("@DateCreated", Profile.Orders.SCart.DateCreated());
    cmd0.Parameters.AddWithValue("@LastUpdate", Profile.Orders.SCart.LastUpdate());
    cmd0.Parameters.AddWithValue("@Description", Profile.Orders.SCart.GetCartDescription());
    cmd0.Parameters.Add("@PaymentType", SqlDbType.Bit).Value = Profile.Orders.SCart.PaymentType;
    cmd0.Parameters.Add("@Delivery", SqlDbType.Bit).Value = Profile.Orders.SCart.Delivery;
    cmd0.Parameters.AddWithValue("@Total", Profile.Orders.SCart.Total);

    string selectSQL = "SELECT OrderID FROM Orders WHERE UserName=@UserName AND DateCreated=@DateCreated";
    SqlCommand cmd1 = new SqlCommand(selectSQL, connection);

    cmd1.Parameters.AddWithValue("@UserName", Profile.UserName);
    cmd1.Parameters.AddWithValue("@DateCreated", Profile.Orders.SCart.DateCreated());
    SqlDataReader reader;

    string insertSQL2 = "";

    insertSQL2 += "INSERT INTO CategoriesInAnOrder (";
    insertSQL2 += "OrderID, CategoryID, Quantity) VALUES (@OrderID, @CategoryID, @Quantity)";

    try
    {
        connection.Open();
        // Insert new record in Orders table
        cmd0.ExecuteNonQuery();

        // Retrieve OrderID for the record inserted
        reader = cmd1.ExecuteReader();
        reader.Read();
        OrderID = (int)reader["OrderID"];
        reader.Close();

        // For known customers, store information for later usage
        if (!Profile.IsAnonymous)
        {
            foreach (CartItem item in Profile.Orders.SCart.Items)
            {
                SqlCommand cmd2 = new SqlCommand(insertSQL2, connection);
                cmd2.Parameters.AddWithValue("@OrderID", OrderID);
                cmd2.Parameters.AddWithValue("@CategoryID", item.CategoryID);
                cmd2.Parameters.AddWithValue("@Quantity", item.Quantity);
                cmd2.ExecuteNonQuery();
            }
        }
    }
    catch (Exception err)
    {
        pnlWizard.Visible = false;
        lblError.Text = err.Message;
    }
    finally
    {
        // cleanup
        connection.Close();
    }
</code></pre>

<p>And then:</p>

<p>-"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and ..."</p>

<p>What's wrong with this code?</p>
