无法将MySQL日期/时间值转换为System.DateTime.Couldn't存储0/0/0000 0:00:00值? [英] Unable to convert MySQL date/time value to System.DateTime.Couldn't store 0/0/0000 0:00:00 value?
问题描述
Me.TreatmentsTableAdapter.Fill(Me.UserDataSet1.treatments)
此行出现错误:
无法将MySQL日期/时间值转换为System.DateTime。无法存储< 0/0/0000 0:00:00>在TreatmentDateEdited列。预期类型是DateTime。
TreatmentDateEdited
列是 DateTime
列,不幸的是包含一些 NULL
值。
我知道数据集中有一个问题,将 NULL
日期转换为其他任何东西,从而产生我这个错误。
$ b
AllowZeroDateTime = True
但不能帮助 NULL
值已经转换为 0/0/0000 0:00:00
但它不能存储在日期字段中。为了让Tableadapter可以运行,我应该在这里使用什么日期格式? / p>
编辑:我发现可能的问题在这里:
DateTime类型的MySQL列不允许我以任何格式输入日期试过我foudn的默认日期格式是 1000-01-01 00:00:00
但它不会接受!这是错误
单元格的值无效(第3行第8列)。
此单元格中的更改值未被识别为有效..Net框架数据类型:MySqlDateTime
错误消息:从System.String到MySql.Data.Types.MySqlDateTime的无效转换。 / p>
所以如果我不能手动在日期列中写日期,那么TableAdapter会做的。任何想法?
EDIT2:@GoroundoVipa
事情是我不循环数据集,但将其用作表单控件中的数据源。
这是另外两个我注意到的事情:
1.当使用VisualStudio ServerExplorer访问数据库时,我无法在datetime字段中输入新数据(产生上面的错误)
2.当我通过MySQL工作台访问DB我有另一个错误:
错误: DB
。 TABLE
:表数据不可编辑,因为没有为表定义主键
服务器:MySQL
版本:5.1.73
编辑表行如果没有PK。
日期的SQL NULL值为 1900-01-01 00: 00:00.000
,您将无法在 0000-00-00 00:00:00.000中插入日期
我最近体验过,我的解决方案是存储NULL值,并在DataGridView或Etc中显示时替换它。
示例:
如果DataGridView1.Rows(e.Index).Cells(10).Value.ToString =1900 -01-01 00:00:00.000然后
DataGridView1.Rows(e.Index).Cells(10).Value =
End If
Me.TreatmentsTableAdapter.Fill(Me.UserDataSet1.treatments)
This line is producing error:
Unable to convert MySQL date/time value to System.DateTime. Couldn't store <0/0/0000 0:00:00> in TreatmentDateEdited Column. Expected type is DateTime.
TreatmentDateEdited
column is DateTime
column that unfortunately contains some NULL
values.
I know that there is a problem in Dataset to convert NULL
date to anything else, thus producing me this error.
- in connection string I have already added:
AllowZeroDateTime=True
but that does not help - Now from the above error msg I see that
NULL
value is already converted to0/0/0000 0:00:00
but it cant store it in date field.
What date format should I use here in order to have Tableadapter operational ?
EDIT: I found possible problem here:
MySQL column of type DateTime doesn't allow me to enter date in any format I tried. I foudn that the default date format is 1000-01-01 00:00:00
but it wont accept that ! this is the error
Invalid value for cell (row 3, column 8). 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'.
So if I cant write date in date column manually neither TableAdapter will do. Any ideas ?
EDIT2: @GoroundoVipa
The thing is I dont loop dataset but use it as datasource in form controls.
Here are 2 other things I have noticed:
1. When using VisualStudio ServerExplorer to access database I am not able to enter new data in datetime field (producing above error)
2. When I access DB through MySQL workbench I got another error:
"Error: DB
.TABLE
: table data is not editable because there is no primary key defined for the table"
Server: MySQL
Version: 5.1.73
How on earth I can not edit table row if it doesn't have PK. It was never required !
The SQL NULL Value for Date is 1900-01-01 00:00:00.000
, You won't be able to insert a Date in 0000-00-00 00:00:00.000
I've Experience it lately, my solution for that is store the NULL value and replace it when displaying in DataGridView or Etc...
Sample:
if DataGridView1.Rows(e.Index).Cells(10).Value.ToString = "1900-01-01 00:00:00.000" Then
DataGridView1.Rows(e.Index).Cells(10).Value = ""
End If
这篇关于无法将MySQL日期/时间值转换为System.DateTime.Couldn't存储0/0/0000 0:00:00值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!