Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c# - Why when I insert a DateTime null I have "0001-01-01" in SQL Server?

I try to insert the value null (DateTime) in my database for a field typed 'date' but I always get a '0001-01-01'. I don't understand, this field "allow nulls" and I don't know why I have this default value.

I'm using C# asp .net with MVC (Entity Framework), this is my code :

Budget_Synthesis newBS = new Budget_Synthesis
{
    Budget_Code = newBudgetCode,
    Last_Modified_Date = null
};
db.Budget_Synthesis.AddObject(newBS);

Last_Modified_Date is typed System.DateTime? so I don't know why they change this 'null'.

If I try to display the value on my application I get 01/01/0001 00:00:00

And 0001-01-01 with SSMS

Someone can explain me why I can't get a real 'NULL' ?

Best regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think this is the value corresponding to the null


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...