2011-05-14 4 views
0

IdEmployeeDetails 양식으로 가져오고 싶지만 결과가 없습니다. 이건 내 코드입니다 :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가 커서 객체입니다

... 또한 커서가 null이 아닌지 확인하십시오 ...

0

firstName이 'XYZ'와 같이 firstName을 사용하는 경우