Click here to Skip to main content
15,749,017 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.
Updated 21-Nov-12 21:09pm
Sergey Alexandrovich Kryukov 22-Nov-12 2:49am    
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.

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:)
Share this answer
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.
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..
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900