?
Solved

How to convert blank datetime field to NULL again?  SQL 2008 backend of VB Windows App

Posted on 2009-07-16
6
Medium Priority
?
1,136 Views
Last Modified: 2013-11-26
I have a windows application written in VB from Visual Studio.  SQL 2008 Backend.  For datetime fields, if the user removes the date after they have entered one, it does not remove the date..... I understand it wants a valid date, but how can I delete a date that was entered by mistake?  Returning the field to NULL.
0
Comment
Question by:sassymacke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24871270
This should update it back to NULL:

UPDATE ur_table
SET datetime_col_name = NULL
WHERE pk = pk_value
0
 
LVL 13

Expert Comment

by:Surone1
ID: 24871276
update table set fieldname = NULL
0
 

Author Comment

by:sassymacke
ID: 24871615
I'm sorry... I should have clarified a bit better.

I want the program to change the field value to NULL if it is empty, anytime it's empty.  Possibly this does it, I'm not sure how I'd use it....

I use the tableadapters in Visual Studio.  Is there a way to insert code on save event that checks for "" and then changes to NULL?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Ernariash
ID: 24872562

I think you answer yourself to insert code on save event that checks for "" and then changes to NUL&
Or if you are using Store procedure. ( I am assuming you field is Nullable)
you can check for you string and converted there.

if (@yourdatetimeParam = ) set @yourdatetimeParam = null
//This one will check for any non datetime including empty strings
if (IsDate(@yourdatetimeParam)=0) set @yourdatetimeParam = null
 
0
 

Author Comment

by:sassymacke
ID: 24872695
I'm not using a stored procedure.  What code would I insert on save event?  I've tried to get something to work but had no luck.
0
 
LVL 9

Accepted Solution

by:
Ernariash earned 2000 total points
ID: 24874242

You can try inline T-SQL to accomplish the same...hope this help you...
if your parameter is not a date then insert or update with nulls
 CASE WHEN IsDate(@yourdatetimeParam)=0 THEN NULL ELSE @yourdatetimeParam END
UPDATE ur_table
SET datetime_col_name = CASE WHEN IsDate(@yourdatetimeParam)=0 THEN NULL ELSE @yourdatetimeParam END
WHERE ....

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question