dBWriteTable无法将NULL写入SQL Server表中的日期字段

时间:2019-01-17 12:00:38

标签: r sql-server

我无法使用dbWriteTable在SQL Server 日期列字段中插入NULL(NA)值。

Error in result_insert_dataframe(rs@ptr, values) : 
  nanodbc/nanodbc.cpp:1587: 22007: [Microsoft][ODBC SQL Server Driver] 
[SQL Server]Conversion failed when converting date and/or time from 
character string. 

我得到了错误:

    Dim guid_id As String = "'3a0eed1f-73b2-11e0-8670-88006707ed92','3a125s34-73b2-11e0-8670-88006707ed92','3a112w3s-73b2-11e0-8670-88006707ed92'"

    Dim strRemove As String = "'3a112w3s-73b2-11e0-8670-88006707ed92'"

    'To remove strRemove from string, we use Regex replace method
    Dim regex = New Regex(strRemove, RegexOptions.IgnoreCase)
    guid_id = regex.Replace(guid_id, "")

    'Now we remove 'Comma' from string, if it is needed.
    If guid_id.Subtring(0, 1) = "," Then guid_id = guid_id.Substring(1)
    If guid_id.Subtring(guid_id.Length - 1) = "," Then guid_id = guid_id.Substring(0, guid_id.Length - 1)

我知道这适用于数字字段,但为什么不适用于日期?我可以使用什么解决方法?

0 个答案:

没有答案