2013-06-18 161 views
1
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 SQLite更新查詢不起作用?

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

回答

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);即可執行更新。

+0

解決了...非常感謝... –

+0

不客氣,你可以接受答案:) – TronicZomB