Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Simple Question - Does SQL Server 2005 Allows NULL for DateTime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jehugaleahsa@gmail.com - 26 Feb 2008 15:38 GMT
Does SQL Server 2005 Allows NULL for DateTime? Just checking.
Lasse Vågsæther Karlsen - 26 Feb 2008 15:44 GMT
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.

SQL Server 2005 allows NULL for any data type to my knowledge, you flag
this as an additional option on the column, wether to allow NULL or not.

Signature

Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

Jon Skeet [C# MVP] - 26 Feb 2008 15:46 GMT
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.

Yes, so long as your column is nullable.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Alberto Poblacion - 26 Feb 2008 15:46 GMT
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.

  Yes, SQL Server alows it. On the other hand, .Net does not (DateTime in
.Net is a Value Type) so be careful when designing your client code to
receive the DateTime values returned from Sql Server.
Jon Skeet [C# MVP] - 26 Feb 2008 15:53 GMT
On Feb 26, 3:46 pm, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.org> wrote:
> > Does SQL Server 2005 Allows NULL for DateTime? Just checking.
>
>    Yes, SQL Server alows it. On the other hand, .Net does not (DateTime in
> .Net is a Value Type) so be careful when designing your client code to
> receive the DateTime values returned from Sql Server.

Well, so long as you're not using .NET 1.1 there's the fairly obvious
choice of Nullable<DateTime> (aka "DateTime?").

Jon
Paul E Collins - 27 Feb 2008 10:47 GMT
> Well, so long as you're not using .NET 1.1 there's the fairly obvious
> choice of Nullable<DateTime> (aka "DateTime?").

SqlDateTime is a bit safer because its MinValue and MaxValue match those
of SQL Server.

Eq.
Jon Skeet [C# MVP] - 27 Feb 2008 11:10 GMT
On Feb 27, 10:47 am, "Paul E Collins" <find_my_real_addr...@CL4.org>
wrote:
> > Well, so long as you're not using .NET 1.1 there's the fairly obvious
> > choice of Nullable<DateTime> (aka "DateTime?").
>
> SqlDateTime is a bit safer because its MinValue and MaxValue match those
> of SQL Server.

On the other hand, that leaks the database nature of it into the rest
of the code. I prefer to have my entity code non-database-specific.

I also tend to avoid using MinValue and MaxValue in the first place,
as they're rarely useful values. Point taken that it's nice to have
them aligned on occasion though.

Jon
Paul E Collins - 27 Feb 2008 17:55 GMT
> I also tend to avoid using MinValue and MaxValue in the first place,
> as they're rarely useful values.

Yes, I suppose I only ever used MinValue as a "no date" flag before C#
had nullable structs.

Eq.
jehugaleahsa@gmail.com - 26 Feb 2008 16:16 GMT
On Feb 26, 8:38 am, "jehugalea...@gmail.com" <jehugalea...@gmail.com>
wrote:
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.

Thanks.
Cowboy (Gregory A. Beamer) - 26 Feb 2008 16:53 GMT
If the database table is set up that way? Yes.

Signature

Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************

| Think outside the box!

*************************************************
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.
Arne Vajhøj - 27 Feb 2008 01:29 GMT
> Does SQL Server 2005 Allows NULL for DateTime? Just checking.

I am pretty sure that all relational databases by definition has to
support NULL for all data types.

Arne

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.