Sigma Equties
Sigma Equties

Reputation: 67

Android sqlite UPDATE not works properly

I referred the following pages but still my problem is not solved,

Android sqlite update table always return 0 , SQLite in Android How to update a specific row , Android SQLite update row not working , Update Function in android SQLite is not working and SQLiteDatabase update not working?

I have a sqlite database as QUESTIONS(ID,QUES,ANS),ID is the primary key. When i try to update a value using following code no change happens in the database.

SQLiteDatabase db = null;
ContentValues values = new ContentValues();
values.put("QUES","New title");
values.put("ANS","Answer" );
long k= db.update("QUESTIONS",values,"ID=2",null);
Log.d("Success",""+k);

The value of k is 1, And there is no change in database. I also tried with

long k= db.update("QUESTIONS",values,null,null);

But no use .

Upvotes: 0

Views: 301

Answers (2)

Sigma Equties
Sigma Equties

Reputation: 67

My problem solved

db = openOrCreateDatabase("data", Context.MODE_PRIVATE, null);

Upvotes: 0

Kuffs
Kuffs

Reputation: 35661

Your first line sets db to be null.

You have no database configured for the UPDATE command to work on.

Upvotes: 5

Related Questions