Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字典插入中日期字段存在bug #1885

Open
IM2Pai opened this issue Sep 13, 2024 · 3 comments
Open

字典插入中日期字段存在bug #1885

IM2Pai opened this issue Sep 13, 2024 · 3 comments

Comments

@IM2Pai
Copy link

IM2Pai commented Sep 13, 2024

问题描述及重现代码:

Table数据表中存在日期字段,在使用 InsertDict 插入多行数据时,有些行数据的日期字段有值,有些为空值,在插入数据库后,空值的字段值被插入成了固定值“1970-01-01 00:00:00.000”

// c# code

fsql.InsertDict(dic).AsTable("tableName").ExecuteAffrows();

数据库版本

SqlServer 2012

安装的Nuget包

.net framework/. net core? 及具体版本

.Net 6

微信图片_20240913194158

微信图片_20240913194159

ToSql()的语句如下

INSERT INTO [T_Pai_FormTest_SubLister]([T_Pai_FormTestID], [ID], [SubCheckBox], [SubTextBox], [SubTextArea], [SubDatePicker], [SubComboBox], [SubButtonEdit], [SubButtonEditName], [SubSingleFile], [SubSingleFileName], [SubSpinner], [SortIndex], [IsReleased], [UpperVersionID]) VALUES(N'b1ea0143-d55c-4e0f-9412-0c9ec1c25eb7', N'b1ea0143-e1ec-45c8-93f4-3afaa89f9eed', NULL, N'数据行1', NULL, '2024-09-13 00:00:00.000', NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL), (N'b1ea0143-d55c-4e0f-9412-0c9ec1c25eb7', N'b1ea0143-e1ec-4657-8a7f-f2ea4762582c', NULL, N'数据行2', NULL, '1970-01-01 00:00:00.000', NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL)

数据库中的表字段也是允许为空值的
微信截图_20240913194913

@2881099
Copy link
Collaborator

2881099 commented Sep 13, 2024

字典是什么值,请用 (DateTime?) 值,而不是用 DateTime

@2881099
Copy link
Collaborator

2881099 commented Sep 13, 2024

DateTime.MinValue 在一些数据库中,值超出了数据库的范围,会报错,且很常见。因此,如果是 MinValue将使用1970年1月1号插入。

当然,如果使用的是DateTime可空类型,传入的值是 null,就会直接插入 DBNull。

@IM2Pai
Copy link
Author

IM2Pai commented Sep 14, 2024

image
image
当我传入两条数据,其中一条日期有值,另一条时间值是空,空值会使用“1970-01-01 00:00:00.000”插入。
但是只有一条数据且为空是,就不会出现这种情况。

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants