Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2009, 03:46 AM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default Can't insert a DateTime into my database with Linq to sql

Hi

I am trying to insert some dateTimes into my database for the aspnet_membership table but every single time I try too. I get this error

Code:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
I have no clue why or what I am doing wrong

Code:
   DateTime DateFields = new DateTime(1750, 1, 1, 0, 0, 0);

aspnet_Membership membership = new aspnet_Membership();
                membership.ApplicationId = applicationId;
                membership.UserId = userId;
                membership.Password = password;
                membership.PasswordFormat = passwordFormat;
                membership.PasswordSalt = base64Salt;
                membership.MobilePIN = null;
                membership.Email = email;
                membership.LoweredEmail = email.ToLower();
                membership.PasswordQuestion = null;
                membership.PasswordAnswer = null;
                membership.IsApproved = isApproved;
                membership.IsLockedOut = false;
                membership.CreateDate = dateCreated;
                membership.LastLoginDate = DateFields ;
                membership.LastPasswordChangedDate = DateFields ;
                membership.LastLoginDate = DateFields ;
                membership.FailedPasswordAttemptWindowStart = DateFields;
                membership.FailedPasswordAnswerAttemptCount = 0;
                membership.FailedPasswordAnswerAttemptWindowStart = DateFields;
                membership.FailedPasswordAnswerAttemptCount = 0;
                membership.Comment = null;

                Db.aspnet_Memberships.InsertOnSubmit(membership);
                Db.SubmitChanges();
 
Old August 15th, 2009, 08:28 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You are initializing DateFields as 1/1/1750. That is three years too early.

Use a date after 1/1/1753.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old August 15th, 2009, 01:53 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Lee Dumond View Post
You are initializing DateFields as 1/1/1750. That is three years too early.

Use a date after 1/1/1753.

Sorry I was trying just random things to see if it would work. I have tried some in the range. Like 1/1/1954. I even used Date.Now and still I get that error.
 
Old August 15th, 2009, 05:55 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Try this:

Code:
using System.Data.SqlTypes;
 
SqlDateTime dateFields = new SqlDateTime(new DateTime(1954, 1, 1));
Don't understand what you're trying to do. There is a Membership API that lets you create new members and insert them into the database. There should be no need whatsoever to interact with the aspnet_Membership table directly, unless I am missing something.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

Last edited by Lee Dumond; August 15th, 2009 at 11:17 PM..




Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert data using LINQ SQL - page 471 LoriBarber BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 March 1st, 2009 08:12 PM
Multiple Row Insert using Linq arivarasuk ASP.NET 3.5 Professionals 1 January 9th, 2009 11:21 AM
INSERT Data to SQL Database Lofa ASP.NET 1.0 and 1.1 Basics 1 February 22nd, 2006 03:09 AM
String to DateTIme for Insert plymnet Classic ASP Databases 1 August 21st, 2005 11:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.