Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI

Anyone help me please and i'm getting an error says....[sqlite returned: error code = 1, msg = no such table: CustomerDetails]...but my table is there

here is my code below...please help


------------------------------------------------------------------------------------

package com.sdc;


Java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor; 
import android.database.SQLException; 
import android.database.sqlite.SQLiteDatabase; 
//import android.database.sqlite.SQLiteException; 
import android.database.sqlite.SQLiteOpenHelper; 
//import android.util.Log;
import android.util.Log;


public class DBAdapter {
	
	// Constants
		
	public static final String COLUMN_ID = "ID";
	public static final String COLUMN_NAME = "NAME";
	public static final String COLUMN_SURNAME = "SURNAME";
	public static final String COLUMN_DATE_OF_BIRTH = "DateOfBirth";
	public static final String COLUMN_ADDRESS = "HomeAddress";
	public static final String COLUMN_EMAIL = "EmailNO";
	public static final String COLUMN_PHONE_NUMBER = "PhoneNumber";
	public static final String COLUMN_CITY = "City";
	public static final String COLUMN_PTYE_PAYMENT = "TypePayment";
	public static final String COLUMN_SHIPPING_TYPE = "ShippingType";
	public static final String COLUMN_CARD_NUMBER = "CardNumber";
	public static final String TAG = "DBAdapter";
	
	private static final String DATABASE_NAME = "Super_Computers.db";
	private static final int DATABASE_VERSION = 3;
	private static final String DATABASE_TABLE = "CustomerDetails";
	
	
	
	private static final String DATABASE_CREATE =
		"create table  CustomerDetails (id integer primary key autoincrement, "
			+ " NAME VARCHAR not null, SURNAME VARCHAR not null,DateOfBirth date not null," +
			"   HomeAddress VARCHAR not null,EmailNO VARCHAR not null,PhoneNumber number , City VARCHAR not null," +
			"TypePayment VARCHAR not null,ShippingType VARCHAR not null, CardNumber number);";
				
	
private final Context context;

private DatabaseHelper DBHelper;
private SQLiteDatabase db;


public DBAdapter (Context ctx) 
{
	this.context=ctx;
	DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper

{
	DatabaseHelper(Context context) {
	
	super (context,DATABASE_NAME,null,DATABASE_VERSION);
			
	}
	
@Override
 public void onCreate(SQLiteDatabase db)
{
	try {
		  db.execSQL(DATABASE_CREATE);
	} 
	   catch (SQLException e) {
		   e.printStackTrace();
		
	   }
	}
@Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion , int newVesion) {

	Log.w(TAG, "Upgrading database from version " + oldVersion + "to"
			+ newVesion + ", which will destroy all old data");
	db.execSQL("DROP TABLE IF EXIST CustomerDetails ");
	

   } 
 }
Posted
Updated 21-May-12 3:56am
v2

1 solution

Change the onUpgrade of SQLiteOpenHelper like below


Java
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion , int newVesion) {

  Log.w(TAG, "Upgrading database from version " + oldVersion + "to"
          + newVesion + ", which will destroy all old data");
  db.execSQL("DROP TABLE IF EXIST CustomerDetails ");
  onCreate(db);

}


May be you change the version from 1 to 3 then as per your code the onUpgrade method only drop the table, It will not create the newly updated table so i added

Java
onCreate(db);



in onUpgrade after Drop the table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900