473,839 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime.MinVal ue and nulls

Rey
Howdy all.

My problem deals w/inserting nulls into database (SQL Svr 2K) for the
datetime fields activityDate and followUpDate where nulls are allowed.
From the web form, the user can type in/select the activity or followup

date.
If, for this exercise, the followupdate textfield is empty, then when
the insert method of the class calls the InsertActivityL og stored
procedure, how can I get nulls inserted instead of 1/1/1900 because of
the use of DateTime.MinVal ue when instantiating the ActivityLog obj.

BTW, even though the activityDate and followUpDate have values of
{1/1/1} before running the stored proc, it will fail w/an overflow msg
that date has be to from 1795 to etc. Once the SqlDateTime.Nul l is cast
as a DateTime, the activityDate var now has the value of 1/1/1900. I'd
like to be able to have a null entry in the ActivityDate field. Then
again, I've been staring at this problem too long and probably can't
see the solution...

Thanks in advance for suggestions/comments,

Rey
*************** *************** *************** *

Below is the code snippet for the insert method.
if (activityDate == DateTime.MinVal ue)
activityDate = (DateTime)SqlDa teTime.Null;

cmd.Parameters. Add("@ActivityD ate", activityDate);

if (followUpDate == DateTime.MinVal ue)
followUpDate = (DateTime)SqlDa teTime.Null;

cmd.Parameters. Add("@FollowUpD ate", followUpDate);
Code snippet for getting values from various txtfields.
if (txtActivityDat e.Text != string.Empty)
actLog.activity Date = DateTime.Parse( txtActivityDate .Text.Trim());
else
if (txtActivityDat e.Text == string.Empty)
actLog.activity Date = DateTime.MinVal ue;

Nov 17 '05 #1
2 15909
Hi

You have to check if it's MinValue , then insert a null, the opposite when
loading, then in all your app you treat MinValue as a null :

//Save
if ( ackdate == DateTime.MinVal ue )
com.Parameters. Add("@ackdate", SqlDbType.DateT ime).Value =
System.DBNull.V alue;
else
com.Parameters. Add("@ackdate", SqlDbType.DateT ime).Value = ackdate;
//Load
ackdate = reader["Acknowledg eBy"]==System.DBNull .Value?DateTime .MinValue:
Convert.ToDateT ime( reader["Acknowledg eBy"]);

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Rey" <re********@cox .net> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Howdy all.

My problem deals w/inserting nulls into database (SQL Svr 2K) for the
datetime fields activityDate and followUpDate where nulls are allowed.
From the web form, the user can type in/select the activity or followup

date.
If, for this exercise, the followupdate textfield is empty, then when
the insert method of the class calls the InsertActivityL og stored
procedure, how can I get nulls inserted instead of 1/1/1900 because of
the use of DateTime.MinVal ue when instantiating the ActivityLog obj.

BTW, even though the activityDate and followUpDate have values of
{1/1/1} before running the stored proc, it will fail w/an overflow msg
that date has be to from 1795 to etc. Once the SqlDateTime.Nul l is cast
as a DateTime, the activityDate var now has the value of 1/1/1900. I'd
like to be able to have a null entry in the ActivityDate field. Then
again, I've been staring at this problem too long and probably can't
see the solution...

Thanks in advance for suggestions/comments,

Rey
*************** *************** *************** *

Below is the code snippet for the insert method.
if (activityDate == DateTime.MinVal ue)
activityDate = (DateTime)SqlDa teTime.Null;

cmd.Parameters. Add("@ActivityD ate", activityDate);

if (followUpDate == DateTime.MinVal ue)
followUpDate = (DateTime)SqlDa teTime.Null;

cmd.Parameters. Add("@FollowUpD ate", followUpDate);
Code snippet for getting values from various txtfields.
if (txtActivityDat e.Text != string.Empty)
actLog.activity Date = DateTime.Parse( txtActivityDate .Text.Trim());
else
if (txtActivityDat e.Text == string.Empty)
actLog.activity Date = DateTime.MinVal ue;

Nov 17 '05 #2
Rey
Howdy Ignacio.
Thanks for the info.

Rey

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5169
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that accepts messages from .NET clients. The web method call includes an object as one of it's parameters - this reflected object has been given a property called "FutureDelivery" and expects a DateTime value. The clients may be in different timezones...
8
19254
by: Manish Jain | last post by:
Platform : ASP.Net/C# void SomeFunction(DateTime date) { string text = date.ToString(); //This crashes if date is null } I am using a construct similar to above. I want to check if the date is null or nor before processing it, but I am not able to figure out the syntax.
2
1881
by: Fabiano | last post by:
Please, i have an webform, that work with a object that receives a DateTime value. I don't want to save date into it. How can i verify if it's value is null or not? Tks Fabiano
8
38055
by: Gidi | last post by:
hello, i have a textbox that represnts a date and i want to pare it to a DateTime, but sometimes this textBox can be empty string and i want to send it to the DataBase as null or as empty Date, how can i do it? thanks
2
2917
by: Diogo Alves - Software Developer | last post by:
Hi, I am writing a class to work with a table that I have... I would like to initialize every var that will be used to nulls... I found a problem doing this to DateTime vars How can I add a parameter do my OdbcCommand telling that a DateTime will be null.... I really need this...
8
4347
by: craigkenisston | last post by:
I have a generic function that receives a couple of datetime values to work with. They can or cannot have a value, therefore I wanted to use null. This function will call a database stored procedure and must save either a null or a real date. However, passing a hardcoded "null" to call this function causes a compilation error : cx.cs(136): Argument '16': cannot convert from '<null>' to 'System.DateTime'
6
16267
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime Field! (It is successful to pass the Null Value to other type of Field)
3
7422
by: Reza Solouki | last post by:
Hello, I have a system where it gets its data from a file that is provided periodically. There are cases where many values such as dates are blank. Considering DateTime variable doesn't accept null, and SQL Server doesn't accept DateTime.MinValue... What is the solution to deal with these kind of cases? I probably could create some work around to send some awkword value that SQL accept and then
5
2884
by: shapper | last post by:
Hello, I defined a DateTime variable: Dim dt As New DateTime How can I check if it is empty? Basically I want to check if it was given to it a DateTime value or not.
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10648
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7828
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3134
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.