2016-01-20 86 views
0

我正在使用Visual Studio 2013,我嘗試在表適配器查詢生成器(在DataSet.XSD)中使用一些函數(如「cast」和Year)。每次我都會遇到錯誤的信息。我在其他sql程序上運行sql語句,它工作正常。有沒有人遇到過這個問題?功能不適用於表適配器查詢bulider

enter image description here

+0

從錯誤信息看來你使用的是SQLite,'YEAR'不是[有效的SQLite DATETIME函數](https://www.sqlite.org/lang_datefunc.html)。 – GarethD

回答

1

SQLite沒有這個功能YEAR(...)。改爲嘗試strftime('%Y', degrees.ExamDate) = '2017'

+0

是的,這個函數可以工作!CAST怎麼樣?在sqlite中是否有替代方法? – Khorshid

+0

@Khorshid使用[CAST表達式](https://www.sqlite.org/lang_expr.html#castexpr) –

2

是你的數據源SQL Server還是SQLite。如果您使用SqLite,則不允許使用Year(),Cast()等函數。

如果你使用SQLite,那麼請看看下面的鏈接,日期時間函數的引用,

https://www.sqlite.org/lang_datefunc.html

正如您所要求的角色功能,有SO post描述投功能,這類似於的SQL Server

SQLite支持CAST和:

Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the 

編碼數據庫連接。

所以你可以做這樣的事情:

選擇從some_table投(some_integer_column文本);

或者,這取決於你想做什麼,你可以只處理 數字爲字符串,讓SQLite的強制類型,因爲它認爲合適的:

選擇some_int ||來自some_table的'煎餅';選擇some_int || '' from some_table;

+0

我正在使用SQLite,所以我只能使用SQLite中允許的函數,即使在Visual Studio中工作。感謝您的鏈接。 – Khorshid

+0

@Khorshid歡迎! –