Solved

LINQ DateTime Format

Posted on 2008-11-03
8
1,398 Views
Last Modified: 2010-05-18
Im converting all code from ADO.net to LINQ. In ADO i could add a DateTime field into SQL when adding a record. Im doing the same with LINQ & im getting an error. SqlDateTime Overflow. Must be between 1/1/1753 12:00:00 AM  AND 12/31/9999 11:59:59 PM. My format is 2008/11/03 11:00:00 AM. How can I make it take this format & store it in sql server as the required format & not throw this error ?
0
Comment
Question by:u2envy1
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:moseack
ID: 22865747
Sinse LINQ2SQL is based on native CLR types, you should convert your DateTime string to a Sytem.DateTime object. You can use DateTime.Parse.
0
 

Author Comment

by:u2envy1
ID: 22865796
It is in a DateTime Data Type & not in a string format
0
 
LVL 7

Accepted Solution

by:
moseack earned 250 total points
ID: 22865855
Not just in the DB, but also in the code?

var q = from o in DB.MockTableWithDate

        where o.Date == DateTime.Parse("2008/11/03 11:00:00 AM")

        select o;

Open in new window

0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 22870989
> My format is 2008/11/03 11:00:00 AM ..

Yep, Mose is close. A DateTime variable does not carry a format.

/gustav
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:u2envy1
ID: 22874140
Sorry guys. I was passing a dateTime value & a null for a EditDate field. I had to add DBNull.Value for the DateTime field.
All Help much appreciated thou
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22874709
No problem.

/gustav
0
 

Author Closing Comment

by:u2envy1
ID: 31512623
Thx guys......
0
 
LVL 7

Expert Comment

by:moseack
ID: 22876977
Always happy to help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Chat Room 1 43
C# GridRow get Old/New Value 1 55
COnsume rest client 6 36
WKHTMLTOPDF - --disable-smart-shrinking not working 10 32
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now