根据日期范围查询sqlite-net db时出错

时间:2014-02-14 14:48:51

标签: c# sqlite datetime windows-phone-8

我遇到了一个问题,我正在编写一个搜索查询来根据日期范围进行搜索,该范围是字符串格式。 问题是我无法在我指定的两个日期范围之间进行查询。

这是我的查询::

String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND Date BETWEEN   Date(2012-01-02)  AND  Date(2014-01-02)  ) ";

querylist = dbConn.Query<Passbook_transaction.Object>(query).ToList<Passbook_transaction.Object>(); ;

但是它返回了SQLite Exception。

错误似乎在“日期”中,因为删除日期查询有效。

2 个答案:

答案 0 :(得分:1)

试试这个,引用日期:

String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND Date BETWEEN   Date('2012-01-02')  AND  Date('2014-01-02')  ) ";

答案 1 :(得分:1)

通过在数据库中添加日期格式为“yyyy-MM-dd HH:mm:ss”(SQLite接受)并使用以下查询来排序问题:

 String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND TDate BETWEEN   Date('2014-01-01 19:45:46')  AND  Date('2014-02-01 19:05:43')  ) ";

感谢大家的意见和答案。