Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi all, i am getting data's from my local database, also i am getting date from my database, some time that date value will be null value, how to assign that null value to my date data type in vb.net.
Posted

1 solution

The question is not quite clear, but one apparent part of it is: .NET System.DateTime type is not nullable, because this is a structure, a value type. How to express the null time then?

The answer is: you can use nullable type you can produce out of the (non-nullable) value type System.DateTime:
C#
System.DateTime structureValue = //... cannot be made null
System.DateTime? nullableTime = null; //assignment to null value is allowed


Please see:
http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx[^].

—SA
 
Share this answer
 
v2
Comments
sameertm 19-Jun-12 3:48am    
no i have null value in my db Coloumn, i want assign that null value to my date variable
Sergey Alexandrovich Kryukov 19-Jun-12 3:51am    
OK, I just explained how to do it. Didn't you get it yet? You probably have DbNull (on certain condition), don't you? In this case, assign null value to your value of the type "System.DateTime?" (NOT "System.DateTime"). What your "no" is supposed to mean?
--SA
db7uk 19-Jun-12 4:22am    
yes. Use "dim myDateTime as DateTime?" or "dim myDateTime as nullable(of DateTime)". Your null value in the database will be DbNull.value. You can check for this and if true set the "myDateTime" to nothing.
Sergey Alexandrovich Kryukov 29-Jun-12 22:28pm    
Yes. Nothing in VB.NET, null in C#.
--SA

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