【发布时间】:2020-04-27 07:35:57
【问题描述】:
下面的子程序有问题。
它的目的是找到一个值(在本例中为日期),并将其与todaysdate 进行比较。如果在DateAscending 中找到日期的一个位置,则将dateexists 设置为true。
执行if语句时出现错误“'Specified Cast is not valid'”。
我之前使用过相同的例程,找到一个字符串的用户名,todaysdate 然而是一个date - 所以我 99% 确定问题与数据类型有关,但我不知道如何解决它。
vairibale getconn 保存连接字符串。
tablename 是具有正确表名的字符串。
Dim todaysdate As Date = Today
Dim dateexists As Boolean = False
Using connection As New OleDbConnection(getconn)
connection.Open()
Dim sql = "SELECT DateAscending FROM " & tablename
Dim finddate As New OleDbCommand(sql, connection)
Dim reader As OleDbDataReader = finddate.ExecuteReader()
While reader.Read()
If todaysdate = CDate(reader.GetString(0)) Then 'Error occurs here
dateexists = True
End If
End While
reader.Close()
connection.Close()
End Using
【问题讨论】:
标签: vb.net