(1)表Table_name没有名为Column_name的列

时间:2013-12-14 13:18:07

标签: android sqlite insert

我使用下面的代码插入记录。但是我得到了上面提到的错误,如标题所示。有一段时间它会正常工作但通常它会显示错误,如下所示。我的代码是,

    String CREATE_MESSAGES_TABLE = "CREATE TABLE " + TABLE_MESSAGES + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_FROM + " TEXT," + KEY_TO + " TEXT,"
            + KEY_BODY + " TEXT," + KEY_DATE + " TEXT," + KEY_STATUS + " TEXT" + ")";
            db.execSQL(CREATE_MESSAGES_TABLE);

这里我将方法称为

 dbHandler.Add_Message(new Message(fromno,tonum,bodyy,datt,stt));

这是我的Add_Message方法,

public void Add_Message(Message contact) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_FROM, contact.getmsgfrom()); // Contact Name
    values.put(KEY_TO, contact.getto()); // Contact Phone
    values.put(KEY_BODY, contact.getmsg()); 
    values.put(KEY_DATE, contact.getdate());
    values.put(KEY_STATUS, contact.getstatus());// Contact Email
    db.insert(TABLE_MESSAGES, null, values);
    db.close(); 
    }

这是获取特定列的代码,

    public int calculateunread(){
    SQLiteDatabase db = this.getReadableDatabase();
    String unreadquery="SELECT COUNT(*) FROM " 
            + TABLE_MESSAGES + " WHERE " + KEY_STATUS + "='0'";

Cursor cursor = db.rawQuery(unreadquery, null);

    int a=cursor.getCount();
    cursor.close();

            return a;
}

但是我无法插入我的记录,我在这里犯了什么错误?

0 个答案:

没有答案