473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Standards for databases, dates and null value handling

AAJ
Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do this
in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy
Oct 12 '06 #1
5 2615
I'd be interested if there's a published standard on this, but in the
1.* days, I used to compare the DateTime variable with the .NET-defined
constant DateTime.MinValue.

All unassigned DateTime variables inside a class have DateTime.MinValue
as their default value. You cannot set a DateTime variable to null.

But with C# 2.0, you can declare "value" types (including DateTime), to
contain nulls. Here's the difference:

DateTime dt1 = null; //won't work
DateTime? dt2 = null; //will work

Hope it helps...
AAJ wrote:
Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do this
in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy
Oct 12 '06 #2

You might consider
http://www.lhotka.net/cslanet/download10.aspx

SmartDate is the object name.

"AAJ" <a.a.comwrote in message
news:u5**************@TK2MSFTNGP05.phx.gbl...
Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do
this
in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy


Oct 12 '06 #3
AAJ
Thanks for the replies guys

its one of those things that I've been using work arounds for a while now,
and I think its time to standardise all future work.

Thanks for the info and references, and if any one else has more ideas or
want to share examples of their work feel free 8-)

thanks again

Andy
"AAJ" <a.a.comwrote in message
news:u5**************@TK2MSFTNGP05.phx.gbl...
Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do
this in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy

Oct 13 '06 #4
AAJ
Hi Deepak

based on what you said, the following allows me to reset dates to null in
the database via a stored procedure

if (m_tbl_invoice_date == DateTime.MinValue)
{
Adapter.PRTestDate(m_PK, null);
}
else
{
Adapter.PRTestDate(m_PK, m_tbl_invoice_date);
}
if anyone else reads the post, I hope it helps them

thanks again

Andy
"Deepak Khanal" <dk*****@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I'd be interested if there's a published standard on this, but in the
1.* days, I used to compare the DateTime variable with the .NET-defined
constant DateTime.MinValue.

All unassigned DateTime variables inside a class have DateTime.MinValue
as their default value. You cannot set a DateTime variable to null.

But with C# 2.0, you can declare "value" types (including DateTime), to
contain nulls. Here's the difference:

DateTime dt1 = null; //won't work
DateTime? dt2 = null; //will work

Hope it helps...
AAJ wrote:
>Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This
doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do
this
in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy

Oct 13 '06 #5
Cool. No problem! -DK

AAJ wrote:
Hi Deepak

based on what you said, the following allows me to reset dates to null in
the database via a stored procedure

if (m_tbl_invoice_date == DateTime.MinValue)
{
Adapter.PRTestDate(m_PK, null);
}
else
{
Adapter.PRTestDate(m_PK, m_tbl_invoice_date);
}
if anyone else reads the post, I hope it helps them

thanks again

Andy
"Deepak Khanal" <dk*****@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I'd be interested if there's a published standard on this, but in the
1.* days, I used to compare the DateTime variable with the .NET-defined
constant DateTime.MinValue.

All unassigned DateTime variables inside a class have DateTime.MinValue
as their default value. You cannot set a DateTime variable to null.

But with C# 2.0, you can declare "value" types (including DateTime), to
contain nulls. Here's the difference:

DateTime dt1 = null; //won't work
DateTime? dt2 = null; //will work

Hope it helps...
AAJ wrote:
Hi

Does anyone know of any good publically available set of standards for
managing dates when dealing with a database server (in my case SQL Server
2000 and c# VS2005).

At the moment, if I create a record in the database for say a job, the
invoicedOn date field will be left null within the data base, not being
assigned untill its actually invoiced.

I can't figure out how to manipulate these date nulls within c#, for
instance displaying a list jobs with their invoiced date, should just
display formatted dates where they exist and be blank if not. This
doesn't
seem to work for null dates when formatting is set on the datagrid. Same
goes if I try set a c# datetime field to null. What happens if I need to
remove a date, I can do this on the server, but I cant figure how to do
this
in c#

A temporary measure has been to use isnull() in the server and choose a
really obviously incorrect date, but obviously this is a poor way of
handling things..

So what I'm looking for is a 'good practice' document of how to interact
between client and server with regard to date handling and null dates.

thanks

Andy
Oct 13 '06 #6

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

Similar topics

6
by: Kris M | last post by:
How do i handle a null value for a date variable type. I am retrieving date data from an access database and storing the records in an array for processing. The array field has a date type and the...
3
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I am developing an application that utilizes a separate class library for data access to a SQL Server database. One of the tables has several...
7
by: smcgouga | last post by:
Visual Basic 6. ADO 2.8 I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format and have a range from '0001-01-01' to '9999-12-31'. I am trying to update a date field on the...
5
by: Fernando | last post by:
Hello, I want do a program what find the date of the one before day at day what the program run (if today is 20031030, the program will find 20031029). I have the next: #include <stdio.h>...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
2
by: Yog | last post by:
Is there a best way to handle various formats of dates for SQL server?. The data comes in various input files with different date formats. The ParseExact function looks like an "evil" and it...
6
by: Charlie Brown | last post by:
When checking for NULL values from a database, normally I would use If Not row("NetSales") Is DBNull.Value Then NetSales = row("NetSales") End If However, if I use a typed dataset then I...
19
by: auratius | last post by:
http://www.auratius.co.za/CSharpCodingStandards.html Complete CSharp Coding Standards 1. Naming Conventions and Styles 2. Coding Practices 3. Project Settings and Project Structure 4....
4
by: Jeff Goodman | last post by:
If there is a better newsgroup to post this in, please let me know. I am a relatively new VB.NET/SQL 2000 programmer. I am working with data imported into SQL2K from Access. Many of the dates...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.