473,473 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

initializing sql date variables issue...

I am working on a vb.net 2005 project using sql server 2000 as the backend .

I am having a bit of problems with date variables... Here is the scenario...

I have a table that includes a couple "smalldatetime" fields.

In my class for this table, when inserting new or saving a row in the table,
both of these date values may possibly be empty. (ie I am allowing nulls on
the db side... )

On an initial insert what is happening is that in my class I have a property
defined as type 'Date'. This 'Date' variable's value (field called
"dtOfferValidUntil") is then used in the stored procedure that inserts or
updates the table as a passed in parameter. What I have discovered is that a
"date" field's initiall value is something along these lines... "#12:00:00
AM#". So, when my stored procedure executes and an attempt is made to set my
smalldatetime field to this value, an error is generated that says
"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM".

My question is this... I want the date property in my class to be initially
set to null somehow so that the date being passed into the stored procedure
will just be null and not "#12:00:00 AM#"... In fact, what I want is to do a
check for a valid date in my class and if it is a valid date, then I will
pass that value onto the stored procedure - otherwise I want to set the date
variable to null and pass that value in. My SQL stored procedure checks for
null values before updating the field. If it is null, then the original
value is left there. If it is not null then the field is updated.

What is the best way to go about doing this? I hate dates...

Thanks, Brad
Jul 6 '07 #1
2 2807
Brad,

One option is to use Nullable (Of DateTime).

Kerry Moorman
"Brad Pears" wrote:
I am working on a vb.net 2005 project using sql server 2000 as the backend .

I am having a bit of problems with date variables... Here is the scenario...

I have a table that includes a couple "smalldatetime" fields.

In my class for this table, when inserting new or saving a row in the table,
both of these date values may possibly be empty. (ie I am allowing nulls on
the db side... )

On an initial insert what is happening is that in my class I have a property
defined as type 'Date'. This 'Date' variable's value (field called
"dtOfferValidUntil") is then used in the stored procedure that inserts or
updates the table as a passed in parameter. What I have discovered is that a
"date" field's initiall value is something along these lines... "#12:00:00
AM#". So, when my stored procedure executes and an attempt is made to set my
smalldatetime field to this value, an error is generated that says
"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM".

My question is this... I want the date property in my class to be initially
set to null somehow so that the date being passed into the stored procedure
will just be null and not "#12:00:00 AM#"... In fact, what I want is to do a
check for a valid date in my class and if it is a valid date, then I will
pass that value onto the stored procedure - otherwise I want to set the date
variable to null and pass that value in. My SQL stored procedure checks for
null values before updating the field. If it is null, then the original
value is left there. If it is not null then the field is updated.

What is the best way to go about doing this? I hate dates...

Thanks, Brad
Jul 6 '07 #2
Can you give me a few lines of code using this?? Just not 100% sure what you
mean...

Thanks!

Brad
"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
Brad,

One option is to use Nullable (Of DateTime).

Kerry Moorman
"Brad Pears" wrote:
>I am working on a vb.net 2005 project using sql server 2000 as the
backend .

I am having a bit of problems with date variables... Here is the
scenario...

I have a table that includes a couple "smalldatetime" fields.

In my class for this table, when inserting new or saving a row in the
table,
both of these date values may possibly be empty. (ie I am allowing nulls
on
the db side... )

On an initial insert what is happening is that in my class I have a
property
defined as type 'Date'. This 'Date' variable's value (field called
"dtOfferValidUntil") is then used in the stored procedure that inserts or
updates the table as a passed in parameter. What I have discovered is
that a
"date" field's initiall value is something along these lines...
"#12:00:00
AM#". So, when my stored procedure executes and an attempt is made to set
my
smalldatetime field to this value, an error is generated that says
"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999
11:59:59 PM".

My question is this... I want the date property in my class to be
initially
set to null somehow so that the date being passed into the stored
procedure
will just be null and not "#12:00:00 AM#"... In fact, what I want is to
do a
check for a valid date in my class and if it is a valid date, then I will
pass that value onto the stored procedure - otherwise I want to set the
date
variable to null and pass that value in. My SQL stored procedure checks
for
null values before updating the field. If it is null, then the original
value is left there. If it is not null then the field is updated.

What is the best way to go about doing this? I hate dates...

Thanks, Brad

Jul 6 '07 #3

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

Similar topics

2
by: Drew McCormack | last post by:
I am getting an error in g++ 4.0.0 that I did not get in g++ 3.4. I have a header with the following const variables with namespace scope: namespace Periphery { extern const double...
1
by: Andreas Boehm | last post by:
Hi *.*, does the standard meanwhile define something about initializing variables by the compiler? I think, it is a side-effect of the OS used, if undefined global (static) variables are...
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
4
by: Jamie Hankins | last post by:
I'm probably being dense here. In the following situation: class Base { int x; int y; } class Decendant : Base { int z; }
17
by: Calle Pettersson | last post by:
Coming from writing mostly in Java, I have trouble understanding how to declare a member without initializing it, and do that later... In Java, I would write something like public static void...
1
by: jwf | last post by:
This question continues on from a previous post "DATE to string" but I think it deserves a new thread. In my previous post I was trying to convert a DATE to string in a NON MFC C++ application...
14
by: Sugandh Jain | last post by:
Hi, The warning from Microsoft.Performance Code Analysis check that, its not required to initialize numeric variables to zero, boolean to false and object to null is a good one because CLR does...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
10
by: Jason Doucette | last post by:
Situation: I have a simple struct that, say, holds a color (R, G, and B). I created my own constructors to ease its creation. As a result, I lose the default constructor. I dislike this, but...
0
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,...
0
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...
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...
0
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,...
1
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...
0
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...
0
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...
0
muto222
php
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.