Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User
sqlite ;

Sqlite: change values of a recordset

01.10.2018 (👁237)

Sqlite: change values

 

 

How can you change a record in SQLite?

 

In SQLite, as with all SQL databases, a record is changed using the UPDATE statement.

In the process, a record is changed with UPDATE table SET target field = new value.

In databases, it is best to always change using the unique ID so that only a single record is changed.

 

 

Update in SQLite

 

Code example in Java, SQLite

public void save_Note_byID(Integer IDNote, String sTitle){
   
//--------< update_Note_byID() >--------
   
SQLiteDatabase db = this.getWritableDatabase();
    String sSQL =
"UPDATE tbl_Notes " +
           
" SET [Title] = '" + sTitle + "'"    +
           
" WHERE IDNote=" + IDNote ;
   
//< run >
   
db.execSQL(sSQL);
   
//</ run >
    //--------</ update_Note_byID() >--------
}

 

 

 

 

Calling the change to SQLite database

In this case, a .Save method of the SQLite database is called.

Under Android Java SQLite, the database class writes storage methods for external access. The user-specific .Save or .Update method can be found in the database class.

 

 

Android app-> java-> project-> MainActivity.java

public void btnSave_Clicked(View view) {
   
//------------< btnSave_Clicked() >------------
    //*save recordset by ID
    //< get fields >
   
TextView lblID=findViewById(R.id.IDNote);
    String sID=lblID.getText().toString();
    Integer ID=Integer.parseInt(sID);
    EditText edit=findViewById(R.id.
editTitle);
    String sTitle=edit.getText().toString();
   
//</ get fields >

    //< save Datase >
   
_db.save_Note_byID(ID,sTitle);
   
//</ save Dataset >


    //------------</ btnSave_Clicked() >------------
}

 

 

 

Using the SQLite database on a page

The database class is usually tied in the Android app when an activity page is opened.

clsDatabase _db; //=new Database(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
..    //< init >
   
_db=new clsDatabase(this);

..