VS .NET to VS.NET 2005

I have a problem with the conversion of dates after migrate of VS.NET 2003 to VS.NEt 2005

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.


Answer this question

VS .NET to VS.NET 2005

  • MRW

    Please create new thread for each new question. Use correct forum, in this case that would be SQL CE forum.



  • cjserio

    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


  • Rocio Altamirano

    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)



  • Emongii

    Thanks Ryan .... work!!!!!!!



  • War_Child

    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


  • Navya Jeevan

    The problem is the format of date ....

    Test
    Dim oDate As DateTime = CType("2006.01.01", System.DateTime)

    Error: invalidcastexception

    How I can change the format of the date to YYYYMMDD

    Thanks.-




  • Janetb

    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 – 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.



  • Phatriff

    Other problem ....

    I import a group of sentences INSERT from a text file .... test

    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')
    Insert Into XXXXX Values('UUUUUU','3')

    The file contains 1000 insert (Aprox); I read lines for lines the file I make the insert

    In VS.NET 2003 it works correctly and the process consumes little memory but In VS.NET 2002 the pocket is without space.

    How I can specify the factor of growth of the database SQL Mobile

    How another thing can be happening

    I sorry for my inlges ... i speak spanish

    Thanks.





  • VS .NET to VS.NET 2005