Android SQLite更新查询不起作用?

时间:2013-06-18 13:42:34

标签: android sqlite

public void AddViewCount(String chname)
{
   String selectQuery = "UPDATE  channel_login SET TimesViewed=TimesViewed+1 WHERE channelName="+chname ;
   SQLiteDatabase db = this.getWritableDatabase();
   Cursor cursor = db.rawQuery(selectQuery, null);
   System.out.print("Count"+cursor.getCount());  

}

我收到此错误消息。你能指出罪魁祸首吗?

android.database.sqlite.SQLiteException: no such column: Sat1  
(code   1):,while compiling: UPDATE  channel_login SET       
TimesViewed=TimesViewed+1 WHERE channelName=Sat1

1 个答案:

答案 0 :(得分:3)

尝试以下方法:

public void AddViewCount(String chname)
{
   String selectQuery = "UPDATE  channel_login SET TimesViewed=TimesViewed+1 WHERE channelName='"+chname+"'";
   SQLiteDatabase db = this.getWritableDatabase();
   Cursor cursor = db.rawQuery(selectQuery, null);
   System.out.print("Count"+cursor.getCount());  

}

在文本值周围添加''应该有效。此外,除非您需要光标计数,否则您只需使用db.execSQL(selectQuery);来执行更新。