Test:
Dim oDate As DateTime = DateTime.Parse(oDst.Tables(0).Rows(1).Item("mydate").ToString())
Error:
invalidcastexception .....
In my project of vs.net 2003 worked well that code
I sorry for my inlges ... i speak spanish
Thanks.
It seems that the date format you were using before is nolonger supported by the normal "Parse" method. If the format is consistent, you can probably get it to work using ParseExact.
If you can determine the exact date format that was supported in 2003 but is not supported in 2005, you may consider filing it as a bug to be fixed in the next version.
-Ryan / Kardax
Assuming your column holds DateTime already please try this:
Dim oDate As DateTime = CType(oDst.Tables(0).Rows(1).Item("mydate"), System.DateTime)
Also keep in mind if you use Parse() and ToString() like this your code would be very inefficient.
If your column holds a string representing date, it probably fails because of locale specific issues ¨C NETCF V2 uses current locale setting to parse dates unlike NETCF V1. You should be able to fix that by specifying actual format of the date.
As mentioned above, if the true data type of the field is compatible with DateTime, then definitely use CType for speed and simplicity.
CType cannot be used for parsing strings, though... you must use Parse or ParseExact for that.
For your example, something like
Dim oDate As DateTime = DateTime.ParseExact("2006.01.01", "yyyy.MM.dd", _
System.Globalization.CultureInfo.CurrentCulture)
...should work.
-Ryan / Kardax
OK, so date is stored as string in the DataSet, not as DateTime. Then you should not cast but should use ParseExact() with format you want:
DateTime.ParseExact("2006.01.01", "yyyy'.'mm'.'dd", Nothing)
Please create new thread for each new question. Use correct forum, in this case that would be SQL CE forum.