Вопрос

There is one table with datetime field set to allow nulls.

I am unable to enter any date format in this field as I tried this: "2011-01-01 00:00:00" "0000-00-00" "21.01.2013" and many others but al of the report error:

Microsoft Visual Studio
---------------------------
Invalid value for cell (row 1, column 3).

The changed value in this cell was not recognized as valid.
.Net Framework Data Type: MySqlDateTime
Error Message: Invalid cast from 'System.String' to 'MySql.Data.Types.MySqlDateTime'.

Type a value appropriate for the data type or press ESC to cancel the change.

What can I do ?

EDIT: Above problem occurs when I directly enter data in mysql table using VisualStudio - ServerExplorer. If I open MySQL workbench then there is no problem and I can write date in format "2011-01-01 00:00:00". Why VS treats Mysql DB differently than Mysql Workbench ?

And here is what I am trying to do from the code

 Private Sub DataGridView1_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
    Debug.Print(e.ToString)

    If e.ColumnIndex = 3 Then
       DataGridView.Rows(e.RowIndex).Cells(3).Value = "2011-01-01 00:00:00" 'entering this test value does not work
    End If
End Sub
Это было полезно?

Решение

I had similar issue migrating from old code in Java. Code tried to save "2011-01-01 00:00:00" to DATE field in database. It worked when I removed time, and was saving date only as "2011-01-01".

Originally I went through that issue setting development environment under Windows. Given project was entirely developed under Linux and it worked fine with default instance of MySQL in Linux. By surprise it didn't work with default database instance under Windows. I tried to find out what can be different, but gave up, as changing code was easier, and worked fine.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top