我能够将数据插入并检索到我的数据库中,但是,我无法更新记录。它说没有这样的专栏:userid1
public boolean updateEntry1(String user, String custName, String gender, String birthDate, String address)
{
//create new record
ContentValues updateEntryValues = new ContentValues();
//Assign values for each row
updateEntryValues.put(CUST_NAME,custName);
updateEntryValues.put(CUST_GENDER,gender);
updateEntryValues.put(CUST_DOB,birthDate);
updateEntryValues.put(CUST_ADDRESS,address);
//Insert the row
Log.w(MYDBADAPTER_LOG_CAT,"Inserted custName = " + custName + "gender =" + gender + "birthDate =" + birthDate + "address =" + address + " into table " + DATABASE_TABLE);
if( _db.update(DATABASE_TABLE,updateEntryValues, USER_ID1 + " = " + user, null)<=0)
{
Log.w(MYDBADAPTER_LOG_CAT,"Update entry where id = " + user + "Failed");
return false;
}
else
{
Log.w(MYDBADAPTER_LOG_CAT,"Removing entry where id = " + user + "Success");
return true;
}
}
答案 0 :(得分:0)
从您描述的错误判断,您正在使用的表似乎没有名为“userid1”的字段。请发布您的onCreate(SQLiteDatabase db)方法。
因此,解决方案:确保'userid1'字段确实存在。
答案 1 :(得分:0)
首先检查表中是否有列,如果存在,则检查条件是否为:
_db.update(DATABASE_TABLE,updateEntryValues, USER_ID1 + " = '" + user+"'", null)<=0