How to Format MySQL DateTime While filling a DataGrid with a DataSet RRS feed

  • Question

  • Dim


    myAdapter1 As New MySqlDataAdapter("Select * From gacli01 Order by cli_nocuenta DESC", Conn)


    Dim ds As New DataSet()


    "gacli01")<------Here is the Problem

    Error (Unable to convert MySQL date/time value to System.DateTime)
    dgvClientes.DataSource = ds

    Friday, October 23, 2009 4:35 PM


All replies

  • Hi,

    When you do a select in mysql, how is the date time retrieved? Can you provide the format? Could be format inconsistencies.
    Friday, October 23, 2009 4:46 PM
  • How about using the Date_Format function in the SELECT query?

    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Marcoahs Saturday, October 24, 2009 5:30 PM
    Friday, October 23, 2009 6:05 PM
  • The format is 0000-00-00 This means yyyy-mm-dd.
    Friday, October 23, 2009 6:53 PM
  • Ok. Why dont you try using YYYYMMDD format which is one of the safest or use that as a string which is least preferred? I have seen posts where YYYY-MM-DD gives problems.
    Saturday, October 24, 2009 3:33 AM
  • Thank Again Paul P Clement IV, This is the best way I have found to work with Dates.

    Ah for Others that may have the same question here is my code to you.

    Use the link to see all of the functions that mysql has to work with dates and this is my code.

    function DATE_FORMAT wich expects a date and it will return it like %d=day in 00-31 %m=month 00-12 and %Y=year in 0000 four digit mode. And Also it dosent mater if the date is null it will sitll work turning it as 00/00/0000.

    And you can take of the / in between and use any other o non.

    Example 1:
    Example 2:
    DATE_FORMAT(date,'%d %m %Y')
    SELECT column,column,DATE_FORMAT(column,'%d/%m/%Y') FROM Table WHERE condition

    Have an Excelent Day

    Saturday, October 24, 2009 5:45 PM