VB .NET比较字符串

时间:2015-05-11 12:22:36

标签: vb.net string

我不知道发生了什么。方法equals不起作用,既不将字符串与'='运算符或'string.compare'进行比较。 thetruth总是设置为“false”。

Public Function ProcessLabel(myValue As Object) As String
    If ((myValue Is DBNull.Value) = False) Then
        Dim thetruth As Boolean
        Dim myValueStr As String
        myValueStr = CStr(myValue)
        thetruth = String.Equals(myValueStr, "01/01/1900")
    End If
    Return myValue.ToString
End Function

我无法附加图片,但我保证,在myValueStr中,我有“01/01/1900”。

1 个答案:

答案 0 :(得分:1)

我非常确定myValueDate对象而不是字符串,并且涉及最小值为01/01/1900的数据库,例如{{ 1}}数据类型。如果你在调试器中查看它,你会看到它像SMALLDATETIME。但是如果你执行01/01/1900(在ToString内部使用),你会得到包含时间部分的本地化表示,所以像CStr(myValue)(德国的f.e.)。

而是比较正确的类型:

01.01.1900 00:00:00