0
name = namebox.getText().toString();
db.open();
Cursor c1 = db.executequery("SELECT _id FROM " + DATABASE_TABLE_CUSTOMER + " where name='" +name+"'" );
_id = c1.getInt(c1.getColumnIndex("name"));
Cursor c2 = db.executequery("SELECT amount FROM " + DATABASE_TABLE_CUSTOMER
        +
        " where _id=" + _id);
Double amount = c2.getDouble(c2.getColumnIndex("amount"));
Cursor c3 = db.executequery("SELECT arrear FROM " + DATABASE_TABLE_CUSTOMER + " where CUSTOMER_ID =" + _id);
arrear = c3.getDouble(c3.getColumnIndex("arrear"));
db.close();

这给了我一个错误的字段错误请求。我的适配器上的 executequery 方法如下所示:

public Cursor executequery(String query) throws SQLException
{
    Cursor mCursor = db.rawQuery(query, null);
    if(mCursor != null){
        mCursor.moveToFirst();
    }
    return mCursor;
}

谁能告诉我我做错了什么。我对此很陌生。

4

1 回答 1

0

你在处理Cursor1. getColumnIndex("name")不能成功,因为选择的是 ID,而不是名称。它应该是getColumnIndex("_id").

于 2012-07-03T21:49:51.367 回答