Solved

LINQ DateTime Format

Posted on 2008-11-03
8
1,417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

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
 

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 50

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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