Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2005, 10:50 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update to a null

Hi

I would like to be able to update a date to a null value, such as the user has put in a date in error and would like the field to display nothing.

Thanks

Louisa

 
Old February 14th, 2005, 11:58 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

This is a feature of the database, not the program. You need to set the properties of the column in the table so that it will accept nulls.
 
Old February 14th, 2005, 12:11 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I didn't explain myself properly, what I mean is I use to use the below in VB6, but it is no longer supported, what else can I use?

Dim DTest as date

DTest = null

I have tried :-

DTest = ISDBnull

Thanks

Lou x

 
Old February 14th, 2005, 07:10 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

A date-type variable can only hold a date. That is the point of strong typing—it forces you to be clear about what you are doing in your code, which in turn reduces the potential for mistakes (both of planning and of keyboarding). (Of course, it can make things harder, too.)

The value of a null in VB is vbNull, btw.

IsDBNull() returns True or False, not a date, (as you have seen).

Perhaps you could tell me a bit more regarding what the larger picture is. I think that you will have to approach this differently—and I have an idea of how you might need to—but I could answer better with just a spot more insight into the process. If you could.
 
Old February 15th, 2005, 04:38 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a date field that is updated by a user, but what if I put in a date by accident and then he or she wants to replace it with no date as none is actually required.

Louisa

 
Old February 15th, 2005, 02:45 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What is this date field part of? A table? A data grid? A textbox on a form?
 
Old February 16th, 2005, 07:13 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The date is part of an access table and is populated via a combo box which can be left blank or populated with a date from the combo list. I am having trouble when a user has populated it with a date saved this date to the table and then decides he or she didn't want a date in that field after all and therefore want to save a null value to the table instead of the date currently populating the table.

Thanks

Louisa

 
Old February 16th, 2005, 03:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I created a table with a date-type column.
I added two rows.
I added dates to both records in Table View mode
I deleted one of the dates. (No problem)

I created a Sub that opened that table as a recordset
I read the value of the column and row that I had deleted the date from in the Immediate Window:
Code:
  ?r!x
  Null

I moved to the row with a date in it.
In the immediate window:
Code:
  r.Edit
  r!x = vbNull
  r.Update
  Again, no problems.

Perhaps what you will need to do is intercept changes in the control that is associated with this table column, and if it is set to "" by the user, replace that with a vbNull...





Similar Threads
Thread Thread Starter Forum Replies Last Post
update multiple columns in an update statement debbiecoates SQL Server 2000 1 August 17th, 2008 04:01 AM
I need to update a date value to null pannasn .NET Framework 2.0 0 December 11th, 2007 06:47 AM
update/delete fails when row contains null values davej ASP.NET 2.0 Basics 2 December 6th, 2006 03:47 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM
Dataset Update with Null Value [V] reyboy ADO.NET 2 June 1st, 2004 12:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.