Skip to content Skip to sidebar Skip to footer

Android Sqlite Error: Variable Number Must Be Between ?1 And ?999

I'm getting the following error when I am trying to update my table using a bigger number. SQLiteLog: (1) variable number must be between ?1 and ?999 W/System.err: android.data

Solution 1:

This line:

db.update(LoginTable.TABLE_NAME, values, LoginTable.Cols.CONSUMER_ID + "=?" + userModel.consumer_no, null);

is incorrect. You have 2 choices. The 1st is to concatenate the value passed to LoginTable.Cols.CONSUMER_ID like this:

db.update(LoginTable.TABLE_NAME, values, LoginTable.Cols.CONSUMER_ID + " = '" + userModel.consumer_no + "'", null);

if userModel.consumer_no is a string, or:

db.update(LoginTable.TABLE_NAME, values, LoginTable.Cols.CONSUMER_ID + " = " + userModel.consumer_no, null);

if userModel.consumer_no is an integer value. The 2nd choice is better and safer:

db.update(LoginTable.TABLE_NAME, values, LoginTable.Cols.CONSUMER_ID + " = ?", newString[] { String.valueOf(userModel.consumer_no) });

You can omit String.valueOf() if userModel.consumer_no is a string. The error in your code is that you mixed somehow the above 2 ways of passing the argument userModel.consumer_no to the update() method.

Post a Comment for "Android Sqlite Error: Variable Number Must Be Between ?1 And ?999"