trisolve Posted December 27, 2003 Posted December 27, 2003 How do i set the date/time variable to nothing. e.g for string we could do as follows: mystr = "" but this doesn't work for datetime variable. Help please thanks trisolve Quote
mocella Posted December 27, 2003 Posted December 27, 2003 Depends on what database you're using, but it's either: DBNull.Value or SqlDateTime.Null Quote
*Experts* Bucky Posted December 27, 2003 *Experts* Posted December 27, 2003 Because all value types resolve to reference types in the .NET Framework, you can just set the variable to Nothing (in VB) or null (in C#). Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
trisolve Posted December 28, 2003 Author Posted December 28, 2003 mocella, i tried your method but I don't think I understood it right. If you can give me an example that would be great. Bucky, I tried setting the value to nothing but all it does is it sets the variable time to its default that is 12:00:00 AM. thanks Quote
mocella Posted December 28, 2003 Posted December 28, 2003 This link may help you a bit: http://www.dotnetjunkies.com/Article/6B4436E7-5913-41CC-A139-095C14AF5552.dcik However, you may need to see how that database column is defined - it may default to that datetime when null is inserted. I wish I had my laptop here to check on how I've done this sort of thing, but I'm not back to work until the 5th. Did I just say I miss work??? Quote
*Experts* Bucky Posted December 28, 2003 *Experts* Posted December 28, 2003 When you access a DateTime variable that has been set to Nothing, then it will initialize and return the default value. Instead of retrieving its value, just check to see if it's equal to Nothing. Here x is the DateTime variable: If x = Nothing Then ' x is set to default value End If Note that for reference types you use the Is keyword to compare objects. For comparing a value type (x, the DateTime) with a reference type (Nothing), as is the case here, you use =. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.