[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert NULL DateTime Linq to SQL

Posted on 2012-08-13
7
Medium Priority
?
1,878 Views
Last Modified: 2012-08-14
Hello,

I have a series of columns that request different dates however the end user will not know these dates when they first create the row.

I have about 15 fields that are DateTime

I have it setup with Linq to SQL so when I go to insert the field into Linq to SQL I get an error that the field cannot be NULL however I have it checked that the field can be nullable....


How do I setup Linq to SQL to allow me to insert a NULL into the Database? The database is setup to allow NULL.

Thanks
0
Comment
Question by:nerdeasy
  • 3
  • 3
7 Comments
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 38290060
Datetime in c# is a struct and so cannot be null

Try using datetime.minvalue or declaring it as nullable with datetime? instead

Michael
0
 
LVL 9

Expert Comment

by:keyu
ID: 38290832
refer below link might helps you..

http://stackoverflow.com/questions/5685355/how-to-set-sql-datetime-to-null-from-linq

or you can simply assign

SqlDateTime.Null
0
 

Author Comment

by:nerdeasy
ID: 38292283
Well, this is how I was able to fix it...

I opened up the Designer Class for the Data Classes I changed System.Nullable<DateTime> to DateTime? and it worked exactly how I wanted it to.

:)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:nerdeasy
ID: 38294061
I've requested that this question be closed as follows:

Accepted answer: 0 points for nerdeasy's comment #a38292283

for the following reason:

I was able to fix it on my own
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 38294062
nerdeasy

The resolution listed for this issue was exactly the one I suggested. Any reason for not awarding points?

Michael
0
 

Author Comment

by:nerdeasy
ID: 38294096
Michael yes should have points sorry I didn't see your response.
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 38294165
cheers

Michael
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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

831 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