我已经采取了字符串
值从的EditText
之后将其设置在 SELECT查询WHERE
条件
I have taken String
value from a EditText
and set it inside SELECT QUERY after WHERE
condition
为
TextView tv = (TextView) findViewById(R.id.textView3);
EditTextet2 et = (EditText) findViewById(R.id.editText1);
String name = et.getText().toString();
Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE name = '"+name+"'", null);
c.moveToNext();
tv.setText(c.getString(c.getColumnIndex("email")));
不过,这是行不通的。有什么建议么?在此先感谢。
But it doesn't work. Any suggestions? Thanks in Advance.
尝试微调的字符串,以确保没有多余的空格:
Try trimming the string to make sure there is no extra white space:
Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE TRIM(name) = '"+name.trim()+"'", null);
也可以使用 c.moveToFirst()
像@thinksteep提及。
Also use c.moveToFirst()
like @thinksteep mentioned.