Solved

LINQ DateTime Format

Posted on 2008-11-03
8
1,414 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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