我有一个名字和#34;购买",它有一些变量,如价格,怀特,名称和...... 我从它的类创建一个表,但是当我想插入它时,会发生错误。 错误说"表购买没有名为称重的列#34; 这是我的代码。请帮助。 感谢
public class Buys {
int id;
String fname;
String lname;
String product;
double weigh;
double price;
double total_price;
String date;
}
public class DatabaseHelper extends SQLiteOpenHelper {
// Logcat tag
private static final String LOG = "DatabaseHelper";
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "WorkerManeger";
// Table Names
private static final String TABLE_WORKERS = "workers";
private static final String TABLE_BUYS = "Buys";
private static final String TABLE_PAYMENT_WORKERS = "payment_workers";
private static final String TABLE_OTHER_PAYMENT = "Otehr_payment";
private static final String KEY_W_NAME = "fname";
private static final String KEY_W_FAMILY = "lname";
private static final String KEY_PRODUCT = "product";
private static final String KEY_WEIGH= "weigh";
private static final String KEY_PRICE= "price";
private static final String KEY_TOTAL_PRICE = "total_price";
private static final String KEY_DATE = "date";
private static final String CREATE_TABLE_BUYS = "CREATE TABLE "
+ TABLE_BUYS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_W_NAME
+ " TEXT," + KEY_W_FAMILY + " TEXT," + KEY_PRODUCT
+ " TEXT," + KEY_WEIGH + " REAL," + KEY_PRICE + " REAL," + KEY_TOTAL_PRICE + " REAL," + KEY_DATE + "DATETIME" + ")";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(CREATE_TABLE_BUYS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldversion, int newversion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + TABLE_BUYS);
// create new tables
onCreate(db);
}
答案 0 :(得分:3)
在创建表格时,您会错过一个空格:
KEY_DATE + "DATETIME" + ")";
必须是
KEY_DATE + " DATETIME" + ")";
答案 1 :(得分:0)
Use this command :
private static final String CREATE_TABLE_BUYS = "CREATE TABLE "
+ TABLE_BUYS + " (" + KEY_ID + " INTEGER PRIMARY KEY, " + KEY_W_NAME
+ " TEXT, " + KEY_W_FAMILY + " TEXT, " + KEY_PRODUCT
+ " TEXT, " + KEY_WEIGH + " REAL, " + KEY_PRICE + " REAL, " + KEY_TOTAL_PRICE + " REAL," + KEY_DATE + " DATETIME" + " )";