这是一个简单的!但是,我缺少一些东西。请帮帮我。
在这里,我试图通过id来获取值,但无法这样做。即使更改id的值,它也会返回相同的值。

    db = openOrCreateDatabase("DBSOURCE", 0, null);
    Cursor cursorc = db.rawQuery("SELECT * FROM LIST WHERE ID="+id+"", null);
    cursorc.moveToFirst();

    int NameID = cursorc.getColumnIndex("Name");
    int mobilenumberID = cursorc.getColumnIndex("MoblieNumber");

    edName.setText(cursorc.getString(NameID));
    edMobNum.setText(cursorc.getString(mobilenumberID));

    cursorc.close();

    db.close();

最佳答案

1-
或更好地使用参数化语句

String query = "SELECT COUNT(*) FROM " + tableName + " WHERE columnName = ?";
cursor = db.rawQuery(query, new String[] {comment});
2-与条件c.moveToFirst()或c.getCount()> 0或(!c.isAfterLast())
if (c.moveToFirst()){
    do{
       //if you not need the loop you can remove that
       id = c.getInt(c.getColumnIndex("_id"));
   }
 while(cursor.moveToNext());
}c.close();
一起使用

10-04 13:06