473,796 Members | 2,460 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 15900
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
5162
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
19250
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
38052
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
2915
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
4341
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
16266
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
7418
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
2876
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
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
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
10457
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...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10013
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...
0
9054
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...
0
5443
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...
1
4119
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
3733
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.