Click here to Skip to main content
11,639,765 members (65,461 online)
Rate this: bad
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 20:41pm
Edited 21-Nov-12 21:09pm
Sergey Alexandrovich Kryukov at 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 at 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 | :laugh: )
armarzook at 22-Nov-12 3:19am
Read the question now please...
OriginalGriff at 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
0 Suvendu Shekhar Giri 330
1 CPallini 177
2 F-ES Sitecore 170
3 himanshu agarwal 167
4 Sergey Alexandrovich Kryukov 159
0 OriginalGriff 9,081
1 Sergey Alexandrovich Kryukov 8,847
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,650
4 F-ES Sitecore 2,558

Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 22 Nov 2012
Copyright © CodeProject, 1999-2015
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