如何在游标dbquery中使用'and'子句 [英] How to use 'and' clause in cursor dbquery
问题描述
在我的表中,我有一些列,从中我想要检索那些满足2列数据条件的行,即'TX_ID'和'TX_DATE'。如果TX_ID中的值为E,并且TX_DATE中的日期是今天的日期,那么我想要那些行。在下面的代码中,我在游标查询的where子句中使用'&&'和'AND'但没有用。值E在字符串'name'中,今天的日期在字符串'td'中。
任何人都可以帮助我吗?
In my table I have some columns and from them I want to retrive those rows that satisfy the condition of data in 2 columns namely, 'TX_ID' and 'TX_DATE'. If the value in TX_ID is "E" and if the date in TX_DATE is todays date then I want those rows. In the following code I use '&&' and 'AND' at the where clause of cursor query but no use. The value "E" is in String 'name' and the today date is in String 'td'.
Can anyone help me out?
String td= new SimpleDateFormat("dd-MM-yyyy").format(new Date());
String name="E";
SQLiteDatabase db = helper.getReadableDatabase();
String[] columns = {VivzHelper.UID, helper.TX_NAME, helper.TX_PARTICULARS, helper.TX_AMOUNT,helper.TX_DATE}; // from tx_table..tested ok
Cursor c = db.query( VivzHelper.TX_TABLE, columns, (helper.TX_ID + "='" + name + "'") AND (helper.TX_DATE + "='" + td + "'"), null, null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
推荐答案
您需要在选择条件中包含AND
(AND
是SQLite不是Cursor构造的一部分。)
请尝试以下代码
You need to include theAND
within the selection criteria (theAND
is SQLite not part of the Cursor construction).
Try the following instead
(helper.TX_ID + "='" + name + "' AND " + helper.TX_DATE + "='" + td + "'"),
您还可以找到以下感兴趣的文章一个简单的Android SQLite示例 [ ^ ]
You may also find the following article of interest A Simple Android SQLite Example[^]
这篇关于如何在游标dbquery中使用'and'子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!