Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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?


C#
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;
Posted
Updated 7-Apr-15 2:56am
v2

1 solution

You need to include the AND within the selection criteria (the AND is SQLite not part of the Cursor construction).

Try the following instead
(helper.TX_ID + "='" + name + "' AND " + helper.TX_DATE + "='" + td + "'"),
You may also find the following article of interest A Simple Android SQLite Example[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900