Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:38:32+00:00 2026-05-23T14:38:32+00:00

In my web application on visual web developer 2010 express, i’m using profiles to

  • 0

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.

Here it is :

       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();
}

My web.config settings concerning Profiles usage, are listed below:

    <anonymousIdentification enabled="true"/>

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

There’s no problem until VS runs this 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();
    }

And then:

-“SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and …”

What’s wrong with this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:38:32+00:00Added an answer on May 23, 2026 at 2:38 pm

    At a guess, Profile.Orders.SCart.DateCreated() is returning DateTime.MinValue, which isn’t representable as a SqlDateTime.

    Work out what date you were expecting, and consider using a SqlDateTime.Null if it’s actually meant to be a null value.

    You may find that you basically aren’t getting the appropriate data at all – I suggest you put some diagnostics in to see the contents of the cart before you start trying to insert it into the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have
I have an ASP.NET MVC 3 .NET application under Visual web developer Express 2010.
I'm currently working on a small web application using Visual Studio 2008 Express. I'm
Using Visual Studio 2010, I developed a WCF service hosted on a web application
s it possible to create an Empty Solution with Visual Web Developer 2010 Express?
I am using Visual Web Developer 2008 Express with ASP.NET MVC 1.0. I would
In this very simple ASP.NET application, Visual Web Developer 2008 Express CAN debug the
In Visual Web Developer Express 2010 I created a default new ASP.NET Webapplication project.
When my colleague debugs a web application in his visual studio instance his output
In the past I've done web application development using Visual Studio. Initially I'd use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.