SqlBulkCopy 和 datetime2 目标数据库列

SqlBulkCopy and datetime2 target database column

如果您查看这篇 Microsoft 文档文章:

https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlbulkcopy?redirectedfrom=MSDN&view=netframework-4.5.2

在备注部分说:

SqlBulkCopy will fail when bulk loading a DataTable column of type SqlDateTime into a SQL Server column whose type is one of the date/time types added in SQL Server 2008.

我没有观察到此行为(失败),想知道此文档是否可能已过时以及 SqlBulkCopy 是否已更新以支持这些数据类型。

关于我的工作的更多细节:

一切正常。我没有失败。我什至尝试在 DataTable 中传递“01/01/0001”日期(超出 SQL datetime 类型的范围)并将其保存在数据库中。

我确实找到了这个 8 岁的 SO post: How can I set column type when using SqlBulkCopy to insert into a sql_variant column 但我没有使用 sql_variant 而且在我的情况下没有任何失败.

任何人都可以澄清我引用的 Microsoft 文档的含义吗?

SqlBulkCopy will fail when bulk loading a DataTable column of type SqlDateTime into a SQL Server column whose type is one of the date/time types added in SQL Server 2008.

但是你写的你的专栏类型是System.DateTime - 所以这个评论与你的代码无关。

换句话说,如果您这样创建数据 table:

var dt = new DataTable();
dt.Columns.Add("date column", typeof(SqlDateTime));
// ... other columns here

那么它将与您的代码相关。