473,672 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime to DBNull.Value

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...

Any help is appreciated...
Nov 17 '05 #1
2 2908
Diogo Alves - Software Developer wrote:
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...

Any help is appreciated...


DateTime can not be null because it is a value type. What you should do
is pick an arbitrary value that will represent null, for example
DateTime.MinVal ue.

if(date == DateTime.MinVal ue)
parameter.Value = null;
--
Rob Schieber
Nov 17 '05 #2
How about using the SqlDateTime data type. It will allow you to use
nulls.

Nov 17 '05 #3

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

Similar topics

9
548
by: news.microsoft.com | last post by:
Hello, I have DateTime property. How can I set this value to null?
1
1962
by: steve gibson | last post by:
I am trying to enter null values into a database using DateTime values. Where the string is empty I need to null the value in the database. if (dataAvailActual.ToString().Trim()!=string.Empty) r.DATE_ACTUAL= System.DateTime.Parse(dataAvailActual); else r.PUBLICATION_DATE_ACTUAL= null; The compiler gives me :
6
14968
by: Paulb1us | last post by:
I want to set a DateTime field to Null before passing it to the DB //First I check to see if anything is in this datarow column, because sometimes we have no data. DateTime dt; if ( datarow.ToString().Length > 0) { //We assume the data is a date dt = (DateTime)datarow; }
5
31189
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! When reading a value from an SQL database i get to a DateTime variable... How can i check that the there is no value assigned? Since i cant use if(myDate.ShortDate != null) ? Regards
2
15885
by: Rey | last post by:
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 InsertActivityLog stored procedure, how can I get nulls inserted instead of 1/1/1900 because of
3
7410
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
4
35311
by: Jose Fernandez | last post by:
Hello. how can i cast a null value from a datareader (System.DBNull) to dateTime I have an object. One of its fields is a DateTime type field. From the database i am getting System.DBNull values from its corresponding column. What can I do to cast it? i don't want to implement a custom method for this. myClass.ExpirationDate=Convert.ToDateTime(dr); // throw an exception.
4
10693
by: Bill Gower | last post by:
Why won't this work? What do I need to do to make it work? DateTime? DateMember; if((DateTime.Parse(oldRow.ToString) == null)) DateMember = null; else DateMember = DateTime.Parse(oldRow.ToString()); The program is failing on the if saying that the null value in the field in
12
2488
by: GaryDean | last post by:
Is there any good way in which to deal with null datetimes. For instance, I can't seem to find anything that will pass a null value in a datetime parameter to another method. Convert.dbnull will not work for instance. Getting nulls back and forth between C# and SQL Server is always problematic. -- Regards, Gary Blakely
1
31360
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box. I then want to pass the value of this text box as a datetime variable to my stored procedure which inserts or updates the row. As I mentioned above, the textbox may be left blank - hence I would want to pass a null to the stored proc. How do I...
0
8486
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
8931
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
8828
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
8680
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
7446
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
6238
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
5705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2819
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
1816
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.