我米试图删除通过Android应用程序一个SQLiteDB的记录,这是我使用的code删除记录的方式
// code的片段在我DBAdapter类公共布尔DeleteRecord(字符串联系人姓名){ Log.i(TAGDeleteRecord(字符串联系人姓名)); Log.i(TAG名称,联系人姓名); 返回db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME += +联系人姓名,NULL); }
和从另一个类,我试图打开数据库,并调用此方法,然后再次关闭数据库调用这个方法,这是我怎么也得codeD,
//我DBApplication类code的段
公共无效的onClick(DialogInterface对话框, 其中INT){DBAdapter.open();DBAdapter.DeleteRecord(DeleteRecord);// DeletRecord是字符串值,在DB(Sivaram)DBAdapter.close();}
当我部署它,我一收到以下错误,
08-25 14:52:20.602:ERROR / AndroidRuntime(231):android.database.sqlite.SQLiteException:没有这样的列:Sivaram:,在编译:DELETE FROM WHERE SimpleTable1 = Employee_Name Sivaram
请帮助我,找到了解决办法
在此先感谢...
解决方案 编辑 -
试试这个,CHK如果它工作第一
返回db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME +='+联系人姓名+',NULL);
在这里你的字符串应该是你的where子句(第3位),你只需要提及你的表名作为你的第二个参数,我相信
删除(字符串tableName值,字符串whereClause,字符串[] whereArgs){}返回db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME,新的String [] {联系人姓名});
I m trying to delete a record from a SQLiteDB via Android Application,This is the way that i used the code to delete the record
//Snippet of code in my DBAdapter Class public boolean DeleteRecord(String ContactName) { Log.i(TAG, "DeleteRecord(String ContactName)"); Log.i(TAG, ContactName); return db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME + "=" +ContactName,null); }
and from the another class, i trying to call this method by opening the DB and calling this method and again closing the DB, this is how i have coded,
//Snippet of code in my DBApplication Class
public void onClick(DialogInterface dialog, int which) { DBAdapter.open(); DBAdapter.DeleteRecord(DeleteRecord); //DeletRecord is string value that in DB(Sivaram) DBAdapter.close(); }
When i deploy it , i an getting the following error,
08-25 14:52:20.602: ERROR/AndroidRuntime(231): android.database.sqlite.SQLiteException: no such column: Sivaram: , while compiling: DELETE FROM SimpleTable1 WHERE Employee_Name=Sivaram
please help me, in finding out the solution
Thanks in advance...
解决方案Edit-
Try this and chk if it works first
return db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME + "='"+ContactName+"'",null);
here your string should be in your where clause(3rd position) and you just require to mention your table name as your second parameter i believe
delete(String tableName, String whereClause, String[] whereArgs) {}
return db.delete(TABLE_SIMPLETABLE_CLIENT1,KEY_EMPLOYEE_NAME,new String[]{ContactName});