linq查询将文本转换为日期以与另一个日期vb.net进行比较

时间:2021-10-31 19:56:36

I have a database field, Field260, that stores date representations as text. For instance a value for 3/29/2018 would be stored as a string "03/29/2018"

我有一个数据库字段Field260,它将日期表示存储为文本。例如,3/29/2018的值将存储为字符串“03/29/2018”

 Dim Db = New DataClasses1DataContext

 Return From cf In Db.FileDatas
     Where cf.Field260 <= System.DateTime.Today

Returns error

System.Data.SqlClient.SqlException: 'Explicit conversion from data type text to datetime is not allowed.'

When I tried to Parse the date

当我试图解析日期时

Where DateTime.Parse(cf.Field260) <= System.DateTime.Today

I receive

System.NotSupportedException: 'Method 'System.DateTime Parse(System.String)' has no supported translation to SQL.'

I'm stumped.

1 个解决方案

#1


-1  

Figured it out cuz I'm a genius.

弄清楚因为我是天才。

 Return From cf In Db.FileDatas
     Where cf.Field260.ToString() <= System.DateTime.Today.ToString("MM/dd/yyyy")

Somehow comparing string to string works, who knew!

以某种方式比较字符串到字符串的作品,谁知道!

#1


-1  

Figured it out cuz I'm a genius.

弄清楚因为我是天才。

 Return From cf In Db.FileDatas
     Where cf.Field260.ToString() <= System.DateTime.Today.ToString("MM/dd/yyyy")

Somehow comparing string to string works, who knew!

以某种方式比较字符串到字符串的作品,谁知道!