-1

Here is My Code for Columns:

public static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "BLOOD_PROJECT";
public static final String TABLE_NAME = "tbl_Individual_Donor_Registration";
public static final String TABLE_NAME_BLOOD_BANK = "tbl_Blood_Bank_Registration";
public static final String COL_1 = "Id";
public static final String COL_2 = "Name";
public static final String COL_3 = "Password";
public static final String COL_4 = "BloodGroup";
public static final String COL_5 = "BloodQuantity";
public static final String COL_6 = "MobileNo";


public static final String COL_7 = "Address";
public static final String COL_8 = "Lat2";
public static final String COL_9 = "Long2";
public static final String COL_10 = "Id";
public static final String COL_11 = "Name";
public static final String COL_12 = "Password";
public static final String COL_13 = "MobileNo";

public static final String COL_14 = "Lat2";
public static final String COL_15 = "Long2";

Code For Creating Table Is Here:

   String CREATE_TABLE_Individual_Donor_Registration = "CREATE TABLE " + TABLE_NAME + "(" + COL_1 + " INTEGER PRIMARY KEY, " + COL_2 + " TEXT, " + COL_3 + " TEXT, " + COL_4 + " TEXT, "+ COL_5 + " TEXT, " + COL_6  + " TEXT, " + COL_14 + " TEXT, " + COL_15 + " TEXT" + ")";
        db.execSQL(CREATE_TABLE_Individual_Donor_Registration);

For Insterting Data in To DataBase:

    public boolean addUser(IndiviualUser user)
    {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues cv = new ContentValues();

        cv.put(COL_2,user.getName());
        cv.put(COL_3,user.getPassword());
        cv.put(COL_4,user.getBlood_Group());
        cv.put(COL_5,user.getBlood_Quantity());
        cv.put(COL_6,user.getMobile_No());
        cv.put(COL_14,user.getLat2());
        cv.put(COL_15,user.getLong2());
        long result = db.insert(TABLE_NAME,null, cv);
        Log.d("ID","DataInserted SuccessFully.");

        db.close();

        if(result == -1)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

And i have also tried solutions of : SQLite android column not found

Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
t Patel
  • 1
  • 1

1 Answers1

0

It looks like that you added Long2 column later in the database. I would do one of the following:

  1. Uninstalling and re-installing your app.
  2. The best and better approach is to drop and recreate tbl_Individual_Donor_Registration table in onUpdate method, and increase the db version whenever you change the schema.
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
  • Thank You sir Your Solution Is Worked. but i have another problem Related to the Data Base in Select Query Code Is:String select = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL_4 + " = "+ final_blood_group; And i got this problem: android.database.sqlite.SQLiteException: near "+": syntax error (code 1): , while compiling: SELECT * FROM tbl_Individual_Donor_Registration WHERE BloodGroup = B+ the B+ was come from user i want to show the Results By Blood Group . I Hope You will Help Me.Thank You. – t Patel Mar 06 '20 at 06:49
  • @tPatel I'm not quite sure about this thing, may be you can post another question and ask for the feedback from more experienced database guys. I think you need to convert `+` to ASCII or UTF8 and same way retrieve them. If the answer was helpful don't forget to accept and vote it so that other members can also get benefit from your question. – Waqar UlHaq Mar 06 '20 at 08:13