SQLTeam.com | Weblogs | Forums

Loading null values into a DATE field


#1

I have a field, "LastDate DATE NULL" and when I try to import a null date, that is "" (nothing in the date), it won't work.

I tried making it " LastDate DATE NULL DEFAULT NULL," but still no go.

When I access the table I can type in NULL in the field but it will not accept it using C# and sql Parameters like:

MSCmd01.Parameters.AddWithValue("@LastDate", LastDate); where the string LastDate = "";

Any ideas?


#2

an empty string is not the same as NULL
Sorry I do not know C# so I cannot tell you what to enter.


#3

use DBNull.Value


#4

SQL is based on a tiered architecture. The database tier handles all of the database retrieval and data integrity. But nothing else. The data display and formatting is done in presentation layers that get data from the database layer. Remember columns in a table are not fields in a file -- totally different data model. .


#5

Don't know the C#; this should work in TSQL:
select LastName = cast(NULL as datetime);


#6

Thanks! I'll use this.