0

Here Is My Code:

(1) Creating DataBase:

public class DataBaseHelper extends SQLiteOpenHelper
{
    public static final int DATABASE_VERSION = 1;
    public static final String LOGCAT = null;
    public static final String DATABASE_NAME = "BLOOD_PROJECT";
    public static final String TABLE_NAME = "tbl_Individual_Donor_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";
}

(2)Creating Table:

@Override
public void onCreate(SQLiteDatabase db)
{
    String CREATE_TABLE_Individual_Donor_Registration = "CREATE TABLE " + TABLE_NAME + "(" + COL_1 + "INTEGER PRIMARY KEY AUTOINCREMENT," + COL_2 + " TEXT, " + COL_3 + " TEXT, " + COL_4 + " TEXT, "+COL_5 + " TEXT, " + COL_6  + " TEXT" + ")";
    db.execSQL(CREATE_TABLE_Individual_Donor_Registration);
}

(3)Add User Data:

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());
    long result = db.insert(TABLE_NAME,null, cv);
    db.close();

    if(result == -1)
    {
        return false;
    }else
    {
        return true;
    }
}
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
t Patel
  • 1
  • 1
  • May be your table is already created within your app. Try to Clear Data from App Settings and run the app again. – Dhaval Shah Feb 22 '20 at 19:18

1 Answers1

0

May be your table is already created within your app. Try to Clear Data from App Settings and run the app again or increase the database version number with proper migration code.

Dhaval Shah
  • 618
  • 6
  • 15