0
public static final String TABLENAME = "EMPLOYEES";
public static final String TABLE = "CUSTOMER";


public static final String[] COLUMNS = {"id","name","charge","department","phone","email","a","b"};

private static final String DB = "DBEMPLOYEES";
private static final int DBVERSION = 1;

// Create table SQL statement
private static final String CREATE_TABLE_EMPLOYEES = "CREATE TABLE "+ TABLENAME + "(" +
        COLUMNS[0] + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , " +
        COLUMNS[1] + " TEXT NOT NULL , " +
        COLUMNS[2] + " TEXT NOT NULL , " +
        COLUMNS[3] + " TEXT NOT NULL , " +
        COLUMNS[4] + " TEXT NOT NULL , " +
        COLUMNS[5] + " TEXT NOT NULL , " +
        COLUMNS[6] + " TEXT NOT NULL , " +
        COLUMNS[7] + " TEXT NOT NULL , " +
        ");";

This is my table. I modified it by adding two records a,b. When I run the program, I have an error

table has no columns b

help me

Ghasem
  • 14,455
  • 21
  • 138
  • 171
mino mino
  • 19
  • 1

2 Answers2

0

Your sql creating table will be executed only once when you first use your database,after this if you update the table's structor,it won't be executed again.So if you want use the new table,please delete the database and rerun your app.

starkshang
  • 8,228
  • 6
  • 41
  • 52
0

The reason why you've got this error is because your Database is created before without column a an b and then somewhere in your app you are trying to query on those columns. To solve that you must uninstall your app and then install it again so onCreate method of your database run again and creates EMPLOYEES table with those new columns. and of course before doing that try to remove the last "," from CREATE_TABLE_EMPLOYEES like this:

// Create table SQL statement
private static final String CREATE_TABLE_EMPLOYEES = "CREATE TABLE "+ TABLENAME + "(" +
        COLUMNS[0] + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , " +
        COLUMNS[1] + " TEXT NOT NULL , " +
        COLUMNS[2] + " TEXT NOT NULL , " +
        COLUMNS[3] + " TEXT NOT NULL , " +
        COLUMNS[4] + " TEXT NOT NULL , " +
        COLUMNS[5] + " TEXT NOT NULL , " +
        COLUMNS[6] + " TEXT NOT NULL , " +
        COLUMNS[7] + " TEXT NOT NULL );";
Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78