简体   繁体   中英

Android SQLITE search column

I'm trying to search a database for a string. Im very new to SQLite so please excuse my ignorance I setup the call as follows

public void GetContact() {
    //---get a contact---
    EditText mEdit = (EditText)findViewById(R.id.editTextnum);
    mEdit.setText("A000021");
   db.open();
   Cursor c = db.getAsset(mEdit.getText());
   if (c.moveToFirst())        
    DisplayContact(c);
   else
   Toast.makeText(this, "No contact found", Toast.LENGTH_LONG).show();
   db.close();
}

This fills a edittext with the string "A000021" and then runs the procedure in the DB helper "getAsset" using the contents of the edittext as the search string

The get Asset procedure is as follows

public Cursor getAsset(Editable strname) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,KEY_NAME, KEY_EMAIL,KEY_FLOOR,KEY_ROOMID,KEY_SCHOOLID,KEY_CONDITION,KEY_ASSETNUMBER,KEY_ASSETCATEGORY,KEY_ASSETTYPE,KEY_ADDITIONAL,KEY_MANUFACTURER,KEY_TYPE,KEY_SERIAL,KEY_INFO,KEY_QUANTITY,KEY_COMMENTS,KEY_INSTALL,KEY_VERIFIED}, KEY_ASSETNUMBER + "=" + strname, null,null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

when I run its says

android.database.sqlite.SQLiteException: no such column: A000021 (code 1): , while compiling: SELECT DISTINCT _id, SITE, BUILDING, FLOOR, ROOMID, SCHOOLID, CONDITION, ASSETNUMBER, ASSETCATEGORY, ASSETTYPE, ADDITIONAL, MANUFACTURER, TYPEMODEL, SERIALNUMBER, INFORMATION, QUANTITY, COMMENTS, INSTALLDATE, VERIFIED FROM contacts WHERE ASSETNUMBER=A000021

The column is called ASSETNUMBER it is a text column and im looking to return the record that has an assetnumber of A000021

Any ideas where I'm going wrong?

尝试使用类似功能

db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,KEY_NAME, KEY_EMAIL,KEY_FLOOR,KEY_ROOMID,KEY_SCHOOLID,KEY_CONDITION,KEY_ASSETNUMBER,KEY_ASSETCATEGORY,KEY_ASSETTYPE,KEY_ADDITIONAL,KEY_MANUFACTURER,KEY_TYPE,KEY_SERIAL,KEY_INFO,KEY_QUANTITY,KEY_COMMENTS,KEY_INSTALL,KEY_VERIFIED}, KEY_ASSETNUMBER + " like '" + strname+"' ", null,null, null, null, null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM