[英]Delete Record from Database row wise in Android
我正在嘗試構建我的第一個Android應用程序,但是遇到了一個問題:我為數據庫中的插入記錄編寫了以下代碼,但是我不知道如何刪除行,所以有人可以幫助我嗎? 插入記錄的代碼:
public void btnAddEmp_Click(View view)
{
boolean ok=true;
try
{
Spannable spn=txtAge.getText();
String name=txtName.getText().toString();
int age=Integer.valueOf(spn.toString());
int deptID=Integer.valueOf((int)spinDept.getSelectedItemId());
Student emp=new Student(name,age,deptID);
dbHelper.AddEmployee(emp);
}
catch(Exception ex)
{
ok=false;
CatchError(ex.toString());
}
finally
{
if(ok)
{
//NotifyEmpAdded();
Alerts.ShowEmpAddedAlert(this);
txtEmps.setText("Number of students "+String.valueOf(dbHelper.getEmployeeCount()));
}
}
}
DELETE FROM tableName WHERE fieldName = value
這是刪除查詢。 用execSql
執行
編輯:使用execSql
而不是rawQuery
您可以使用SQLiteDatabase.execSQL()簡單地做到這一點,而不必嘗試rawQuery這是用於查詢的。
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM tableName where fieldName=Value");
db.close();
在此處查看詳細答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.