Inserting values to SQLite table in Android

前端 未结 8 2080
抹茶落季
抹茶落季 2020-12-09 16:42

I am new in android app developement. I tried to insert values to SQLite database through the below code;

public class cashbook extends Activity {

    @Over         


        
8条回答
  •  粉色の甜心
    2020-12-09 17:17

    I recommend to create a method just for inserting and than use ContentValues. For further info https://www.tutorialspoint.com/android/android_sqlite_database.htm

    public boolean insertToTable(String DESCRIPTION, String AMOUNT, String TRNS){
    
        SQLiteDatabase db = this.getWritableDatabase();
    
        ContentValues contentValues = new ContentValues();
        contentValues.put("this is",DESCRIPTION);
        contentValues.put("5000",AMOUNT);
        contentValues.put("TRAN",TRNS);
        db.insert("Your table name",null,contentValues);
    
        return true;
    }
    

提交回复
热议问题