2010-08-31 37 views
4

我使用和EntityDateSource我加where條件過濾在運行時的數據,然後綁定網格到數據源,但我得到以下錯誤: -篩選EntityDataSource對於DateTime字段

The argument types 'Edm.DateTime' and 'Edm.String' are incompatible for this operation. 

搜索條件看起來像這樣: -

it.[MyDate]='8/13/2010 00:00:00' 

任何想法如何解決這個問題?

回答

6

VinayC給出的答案還有一些東西。以下將明確的工作,因爲它爲我工作。

使用語法如它。[數值指明MyDate] = DATETIME '2010-13-8 00:00'

0

EntityDataSource.Where使用EnttiySQL sytanx。日期時間文字需要在中指定YYYY-MM-DD HH:MM - 請參閱documentation

總之,使用語法如it.[MyDate]='2010-13-8 00:00',你應該沒問題。

+0

-1這是不正確,因爲你的答案缺少一個關鍵點。由於文檔(你鏈接到)說,日期時間必須以DATETIME爲前綴,因此正確的答案將是Sachins post:it。[MyDate] = DATETIME'2010-13-8 00:00' – reSPAWNed 2012-02-10 09:12:08

0

Private Sub EntityDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.EntityDataSourceSelectingEventArgs) Handles EntityDataSource1.Selecting

Dim dat As String = Format(CDate(my_Date), "yyyy-MM-dd HH:mm:ss") EntityDataSource1.Where = "it.my_field = CONVERT(DATETIME, '" & dat & "', 102)) "

End Sub

+0

請編輯你的答案和格式的代碼,使其可讀 – kleopatra 2013-07-02 15:29:42

+0

完成!適用於法國日期格式 – user2000862 2014-03-26 09:17:32