Dave
Dave

Reputation: 297

Sqlite update a column based on where clause android

I am developing an android app, where I want to update a column in a row based on a where clause which comprises of two values. Below is what I have tried.

public void setlocationsetcolumn(double lats , double longs, String setvalue)
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(Loc_set, setvalue);

    db.update(TABLE_LATLONG, values, " WHERE "+Loc_lati +" = " + lats+" AND "+Loc_longi+" = "+longs, null);
}

I wan to update the Loc_set, based on the lats & longs values. but i am getting a force close. Am I doing something wrong here. Please help.Thanks!

Upvotes: 6

Views: 17882

Answers (3)

rs11
rs11

Reputation: 65

String[] args = new String[]{lats, longs};
db.update(TABLE_LATLONG, values, "Loc_lati=? AND Loc_longi=?", args);

You can use this logic for the update of table.

Upvotes: 0

hordurh
hordurh

Reputation: 2673

Drop the WHERE String . Try this :

db.update(TABLE_LATLONG, values, Loc_lati +" = " + lats+" AND "+Loc_longi+" = "+longs, null);

However, I Don't know what loc_lati and loc_longi are, hopefully columns in your db.

Upvotes: 1

Vipul
Vipul

Reputation: 28093

below snippet will help you.

String[] args = new String[]{lats, longs};
db.update(TABLE_LATLONG, values, "Loc_lati=? AND Loc_longi=?", args);

Upvotes: 16

Related Questions