Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ctype operator in Visual Basic; string to MySqlDateTime

ctype operator in Visual Basic; string to MySqlDateTime

Scheduled Pinned Locked Moved Visual Basic
databasemysqlhelpquestion
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fabrice leal
    wrote on last edited by
    #1

    Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"

    H I F 3 Replies Last reply
    0
    • F fabrice leal

      Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Somebody might know the answer to your problem instantly, but for the rest of us, could you post the section of code where the error occurs so that we can suggest alternative strategies. [Edit] Just found this! Take a look at this[^], the relevant part is a fair way down so you'll probably be better off doing a search for mysqldatetime [/Edit]

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      modified on Monday, August 24, 2009 8:49 AM

      1 Reply Last reply
      0
      • F fabrice leal

        Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"

        I Offline
        I Offline
        i i i
        wrote on last edited by
        #3

        could not understand exactly your problem but try this field.tostring("dd/mm/yyyy") might solve your problem plus have a look on the following link http://www.wepapers.com/Papers/13639/.NET_Standard_Date_Time_Format_Strings_cheat_sheet[^] http://www.cheat-sheets.org/[^]

        Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...

        1 Reply Last reply
        0
        • F fabrice leal

          Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"

          F Offline
          F Offline
          fabrice leal
          wrote on last edited by
          #4

          I have NO code in my application to handle the input of the date, just the necessary to create the datasource for the datagridview. I use a CalendarColumn to pick a date in the column... When I pick a value for the cell, and I "get out" of the cell, a exception is thrown, and a dialog with the error is displayed: "Invalid cast from System.String to MySql.Data.Types.MySqlDateTime". The call Stack in the message says that the error is thrown in the method PushFormattedValue, that I suppose that cannot be overloaded (or whatever...) PS: Sorry for my english :)

          F 1 Reply Last reply
          0
          • F fabrice leal

            I have NO code in my application to handle the input of the date, just the necessary to create the datasource for the datagridview. I use a CalendarColumn to pick a date in the column... When I pick a value for the cell, and I "get out" of the cell, a exception is thrown, and a dialog with the error is displayed: "Invalid cast from System.String to MySql.Data.Types.MySqlDateTime". The call Stack in the message says that the error is thrown in the method PushFormattedValue, that I suppose that cannot be overloaded (or whatever...) PS: Sorry for my english :)

            F Offline
            F Offline
            fabrice leal
            wrote on last edited by
            #5

            ok, never mind... i think i just solved my problem with this code:

            If e.DesiredType.Equals(GetType(MySql.Data.Types.MySqlDateTime)) Then
            If String.IsNullOrEmpty(e.Value) Then
            e.Value = DBNull.Value
            Else
            Try
            e.Value = New MySql.Data.Types.MySqlDateTime(DateTime.Parse(e.Value))
            Catch
            e.Value = DBNull.Value
            End Try
            End If
            e.ParsingApplied = True
            End If

            in the method

            Private Sub DataGridCusto_CellParsing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellParsingEventArgs) Handles DataGridCusto.CellParsing

            thanks

            I 1 Reply Last reply
            0
            • F fabrice leal

              ok, never mind... i think i just solved my problem with this code:

              If e.DesiredType.Equals(GetType(MySql.Data.Types.MySqlDateTime)) Then
              If String.IsNullOrEmpty(e.Value) Then
              e.Value = DBNull.Value
              Else
              Try
              e.Value = New MySql.Data.Types.MySqlDateTime(DateTime.Parse(e.Value))
              Catch
              e.Value = DBNull.Value
              End Try
              End If
              e.ParsingApplied = True
              End If

              in the method

              Private Sub DataGridCusto_CellParsing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellParsingEventArgs) Handles DataGridCusto.CellParsing

              thanks

              I Offline
              I Offline
              i i i
              wrote on last edited by
              #6

              ;)

              Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups