-2

I'm trying to update a particular row of a database, and I have the following code

 public String CREATE_QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME +
        "(" + TableData.TableInfo.USER_NAME + " TEXT, " + TableData.TableInfo.USER_PIN +
        " TEXT, " + TableData.TableInfo.PARTNER_FIRST + " Text, " + TableData.TableInfo.PARTNER_SECOND +
        " TEXT, " + TableData.TableInfo.DATE + " TEXT, " + TableData.TableInfo.SIGNATURE_IMAGE + " BLOB, " +
        TableData.TableInfo.PARTNER_SIGNATURE + " BLOB);";

And I am getting an error from

ContentValues cv = new ContentValues();
    DatabaseOperations DOP = new DatabaseOperations(ctx);
    Cursor CR = DOP.getInformation(DOP);
    CR.moveToLast();

    SQLiteDatabase SQ = DOP.getWritableDatabase();

    ContentValues args = new ContentValues();
    args.put(TableData.TableInfo.USER_NAME, CR.getString(0));
    args.put(TableData.TableInfo.PARTNER_FIRST, partner_name);


    SQ.update(TableData.TableInfo.TABLE_NAME, args, "ROWID=?" + id, null);

This is the error:

     Caused by: android.database.sqlite.SQLiteException: no such column: partner_first (code 1): , while compiling: UPDATE reg_info SET user_name=?,partner_first=? WHERE ROWID=?54

Here is my table info

public static abstract class TableInfo implements BaseColumns {

    public static final String USER_NAME = "user_name";
    public static final String USER_PIN = "user_pin";
    public static final String PARTNER_FIRST = "partner_first";
    public static final String PARTNER_SECOND = "partner_second";
    public static final String DATE = "date";
    //public static final String LOC = "location";
    public static final String SIGNATURE_IMAGE = "signature_image";
    public static final String PARTNER_SIGNATURE = "partner_signature";
    public static final String DATABASE_NAME = "user_info";
    public static final String TABLE_NAME = "reg_info";

}

What am I doing wrong?

Alex
  • 325
  • 7
  • 16

2 Answers2

2

Uninstall and rename the database.. This happens frequently when you change your table name or any change in database.

pratz9999
  • 539
  • 4
  • 20
0

The problem is in your UPDATE statement - you have a concatenated string and are not passing the "WHERE" arg correctly on this line:

SQ.update(TableData.TableInfo.TABLE_NAME, args, "ROWID=?" + id, null); 

simply do this:

SQ.update(TableData.TableInfo.TABLE_NAME, args, "ROWID=" + id, null); 

the error is misleading because the SQL statement is wrong altogether.

Jim
  • 10,172
  • 1
  • 27
  • 36