Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

initializing sql date variables issue...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad Pears - 06 Jul 2007 16:42 GMT
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
Kerry Moorman - 06 Jul 2007 17:22 GMT
Brad,

One option is to use Nullable (Of DateTime).

Kerry Moorman

> I am working on a vb.net 2005 project using sql server 2000 as the backend .
>
[quoted text clipped - 28 lines]
>
> Thanks, Brad
Brad Pears - 06 Jul 2007 17:32 GMT
Can you give me a few lines of code using this?? Just not 100% sure what you
mean...

Thanks!

Brad
> Brad,
>
[quoted text clipped - 48 lines]
>>
>> Thanks, Brad

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.