我有这个完全相同的问题。不久前,我忘记了确切的细节,但问题是 Pervasive.SQL 使用 &H0(即零)来表示丢失的日期,但 &H0 对于 ODBC 中的日期字段无效。
我的解决方案是将字段转换为 SQL 中的字符串,因此请在 QueryString 中使用它: CONVERT(datefield,SQL_CHAR)
然后我编写了以下函数将其转换回日期(&H0 成为新日期):
''' <summary>
''' Enables a Btrieve Date column that contains 0x0 values to be accessed. Use 'SELECT CONVERT(datefield, SQL_CHAR)' to access the field, then this function to convert the result back to a date. A New Date is returned if the record has a 0x0 date
''' </summary>
''' <param name="Expression"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function SQL_CHAR2Date(ByVal Expression As String) As Date
'check Expression is in the correct format
Dim strMap As String = ""
For i As Integer = 0 To Expression.Length - 1
Select Case Expression.Substring(i, 1)
Case "0" To "9" : strMap &= "0"
Case "-" : strMap &= "-"
Case Else : strMap &= Expression.Substring(i, 1)
End Select
Next i
Select Case strMap
Case "0000-00-00"
Case Else
Throw New ApplicationException("SQL_CHAR2Date: invalid input parameter")
End Select
Dim y As Integer = CInt(Expression.Substring(0, 4))
Dim m As Integer = CInt(Expression.Substring(5, 2))
Dim d As Integer = CInt(Expression.Substring(8, 2))
If y = 0 And m = 0 And d = 0 Then
Return New Date
Else
Return DateSerial(y, m, d)
End If
End Function