Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sqlite android中检查列的值是否存在?_Android_Sqlite - Fatal编程技术网

如何在sqlite android中检查列的值是否存在?

如何在sqlite android中检查列的值是否存在?,android,sqlite,Android,Sqlite,这是我的代码: public boolean checkIDTraLoiBangID(int Id) { boolean check = false; String query = "select IDTraLoi from BangCauHoi where ID=?"; Cursor c = database.rawQuery(query, new String[] { "" + Id }); if (c != null && c.moveToF

这是我的代码:

public boolean checkIDTraLoiBangID(int Id)
{
    boolean check = false;
    String query = "select IDTraLoi from BangCauHoi where ID=?";
    Cursor c = database.rawQuery(query, new String[] { "" + Id });
    if (c != null && c.moveToFirst())
    {
        check = true;
    }
    c.close();
    return check;
}
我试图检查IDTraLoi的值是否存在,是否遵循where子句。但是,即使在IDTraLoi列中没有值,此函数仍然返回true

有人能帮我吗?
谢谢你,很抱歉,因为我的英语…

代码只是检查一行是否存在

要检查列中的值,实际上必须读取该值:

字符串查询=从BangCauHoi中选择IDTraLoi,其中ID=?; 游标c=database.rawQueryquery,新字符串[]{+Id}; 如果c.moveToFirst{ 检查=!c.isNull0; } 使用a可以简化代码:

字符串idTraLoi=DatabaseUtils.stringForQuerydatabase, 从BangCauHoi中选择IDTraLoi,其中ID=+ID,null; 检查=idTraLoi!=无效的
到目前为止,您尝试过哪些替代方案?什么是毫无价值的?无效的零?无值表示:零@CL。