473,804 Members | 2,124 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 15903
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
5168
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
19252
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
1879
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
38053
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
2916
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
4344
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
7421
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
2878
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
9595
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
10603
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
10356
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
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
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
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
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
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.