Click here to Skip to main content
12,631,606 members (31,333 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB Visual-Studio VB.NET
Dear Coders,

I am having trouble assigning a date datatype value to null. If i assign like

Dim MyDate as Date
MyDate = DbNull.value

Its showing error like cannot convert the value. Please Help.
Posted 21-Nov-12 21:41pm
Updated 21-Nov-12 22:09pm
Of course you cannot. This is not a nullable type; and DbNull is a special type used to conduct a notion of null in relational databases, which is not the same thing as CLI null. This is a double incompatibility.

Better explain what exactly do you want to achieve. DbNull makes no sense if you don't use ADO.NET. Where do you use it?

armarzook 22-Nov-12 3:09am
Sorry. not data datatype.. Its Date Datatype.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't assign DBNull.Value to anything in particular - it is a value that is passed between .NET and SQL to indicate a null value in a database table, not a value you can generally use in your application. Try Nothing instead. (But that probably won't do what you want either :laugh:)
armarzook 22-Nov-12 3:19am
Read the question now please...
OriginalGriff 22-Nov-12 3:23am
Still not changed - you still can't assign DBNull.Value to a Date datatype - it isn't a value it can accept.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Is this you looking for.. - Assigning null value to datetime object[^]

armarzook wrote:
MyDate = DbNull.value

here DbNull does not represent anything if you are not using ADO.Net..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100