gpt4 book ai didi

android - 没有这样的列 : pratik (code 1): while compiling: DELETE FROM Insert_table WHERE NAME=pratik

转载 作者:行者123 更新时间:2023-11-29 20:07:00 25 4
gpt4 key购买 nike

我正在传递一个要删除的字符串名称,但它给了我错误,我无法删除该行任何人都可以告诉我我的代码有什么问题,它说没有这样的列我不知道为什么,它说没有这个栏目我不知道为什么

    package com.example.bipinp.mithun;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Bipinp on 2/18/2016.
*/
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Sales.db";
public static final String TABLE_NAME1 = "Insert_table";
public static final String TABLE_NAME2 = "Entry_table";

public static final String COL_ID = "ID";
public static final String COL_NAME = "NAME";

public static final String COL_CUST_NAME = "NAME";
public static final String COL_CARET = "CARET";
public static final String COL_AMOUNT = "AMOUNT";
public static final String COL_AMOUNT_PAID = "AMOUNT_PAID";
public static final String COL_BALANCE = "BALANCE";

public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME1 + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT)");
db.execSQL("create table " + TABLE_NAME2 + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,CARET INTEGER,AMOUNT INTEGER,AMOUNT_PAID INTEGER,BALANCE INTEGER,FOREIGN KEY(ID) REFERENCES Insert_table(ID_NAME))");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME1);
db.execSQL("DROP TABLE IF EXISTS" + TABLE_NAME2);
onCreate(db);

}

public boolean deleteRow(String name)
{ SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME1, COL_NAME + "=" + name, null) > 0;
}

public boolean insertdata(String name){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_NAME,name);
long result = db.insert(TABLE_NAME1,null,contentValues);
if(result == -1)
return false;
else
return true;
}

public boolean insertdata2(String name,String caret,String amount,String amount_paid,String balance){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_CARET,name);
contentValues.put(COL_CARET,caret);
contentValues.put(COL_AMOUNT,amount);
contentValues.put(COL_AMOUNT_PAID,amount_paid);
contentValues.put(COL_BALANCE,balance);
long result = db.insert(TABLE_NAME2,null,contentValues);
if (result == -1)
return false;
else
return true;
}

public List<String> getAllLabels(){
List<String> labels = new ArrayList<String>();

String selectQuery = " SELECT " + COL_NAME + " FROM " + TABLE_NAME1;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery,null);

if (cursor.moveToFirst()){
do { labels.add(cursor.getString(0));
}while (cursor.moveToNext());
}
cursor.close();
db.close();

return labels;
}


}

最佳答案

改变

public boolean deleteRow(String name)
{ SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME1, COL_NAME + "=" + name, null) > 0;
}

public boolean deleteRow(String name)
{ SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME1, COL_NAME + "= '" + name + "';", null) > 0;
}

你忘记了名字的引号,它是一个字符串,所以它是必需的

关于android - 没有这样的列 : pratik (code 1): while compiling: DELETE FROM Insert_table WHERE NAME=pratik,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35524563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com