Question

I am facing a problem in updating a table with multiple columns in where clause of the db.update in sqlite.

Below is what I have tried but not accepting and showing syntax error.

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname}));

In above query

  1. First parameter is tablename to be updated.
  2. second parameter is value to be updated which will point to another class update method where I wrote content values for updating the table
  3. Major one third part is parameters I need to pass in where clause.

but giving syntax error

The method update(String, ContentValues, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, ContentValues, String, String)

How can I declare multiple columns in where clause?

Was it helpful?

Solution

Try changing

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname}));

to

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and "+ column3+"=?"),(new String[] {getdate,stockname}));

Add a space after the "and" in the WHERE clause and you need to pass a String[] and not String in the whereArgs parameter. Currently you are passing a String

OTHER TIPS

Change the stretch code:

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname}));

To

db.getWritableDatabase().update( tablename, update(buy+dupbuy), column2 + " = ? and " + column3 + " = ?", new String[]{ getdate, stockname } );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top