2011-05-14 45 views
0

我想從0123.表格中獲得Id表格,但沒有得到任何結果。這是我的代碼:Android從rawQuery獲取數據到另一個表格

public class EmployeeList extends ListActivity { 
    protected EditText searchText; 
    protected SQLiteDatabase db; 
    protected Cursor cursor; 
    protected ListAdapter adapter; 
/** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     db = (new DatabaseHelper(this)).getWritableDatabase(); 
     searchText = (EditText) findViewById (R.id.searchText); 
    } 
    public void search(View view) { 
// || is the concatenation operation in SQLite 
     cursor = db.rawQuery("SELECT _id FROM employee WHERE firstName=?", 
      new String[]{searchText.getText().toString()}); 
     Intent intent = new Intent(this, EmployeeDetails.class); 
     long id = cursor.getLong(cursor.getColumnIndex("_id")); 
     intent.putExtra("EMPLOYEE_ID", id); 
     startActivity(intent); 
    } 
} 

回答

0

對於從遊標對象獲取記錄值,您需要遍歷並從中檢索數據...

if(c.getCount()>0){ if (c.moveToFirst()){ c.getLong(0); }} 

其中C是你的光標對象...另外檢查遊標是否不爲空...

0

如果firstName是String,則使用firstName類似'XYZ'

相關問題