This article illustrates the way Android implements SQLite Add, update, and delete rows. Share to everyone for your reference, specific as follows:
The Sqlitedatabase class exposes specific methods, such as inserts, deletes, and updates, which wrap the SQL statements required to perform these actions. However, the Execsql method allows you to execute any valid SQL statements on a database table that you want to perform manually.
At any time, if you modify the value of the underlying database, you should call the cursor Refreshquery method that any browses on the current table.
Insert New row
To create a new row, construct a Contentvalues object and use its put method to provide a value for each column. Inserting a new row by invoking the Insert method on the target database object and passing the Contentvalues object into the method-requires the name of the table-as shown in the following fragment:
Create a new row of values to insert.
Contentvalues newvalues = new Contentvalues ();
Assign values for each row.
Newvalues.put (column_name, newvalue);
[ ... Repeat for each column ...]
Insert the row into your table
Mydatabase.insert (database_table, NULL, newvalues);
Update rows
Update rows also need to be implemented through Contentvalues.
Create a new Contentvalues object and use the Put method to specify a new value for each column you want to update. Invokes the Update method of the database object, passing in the table name and the updated Contentvalues object, a where language that indicates which rows need to be updated.
The updated processing is demonstrated in the following fragment:
Define the updated row content.
Contentvalues updatedvalues = new Contentvalues ();
Assign values for each row.
Updatedvalues.put (column_name, newvalue);
[ ... Repeat for each column ...]
String where = key_id + "=" + rowId;
Update the row with the specified index with the new values.
Mydatabase.update (database_table, updatedvalues, where, null);
Delete Row
To delete a row, you can simply call the Delete method on the database object, specifying the table name and a where statement to indicate which rows you want to delete, as shown in the following code:
Mydatabase.delete (database_table, key_id + "=" + rowId, NULL);
For more information on Android-related content readers can view the site topics: "Android Database Operating skills summary", "Android programming activity Operation Skills Summary", "Android File Operation skills Summary", " Android programming development of the SD card operation method Summary, "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android View tips Summary" and "Android Control usage Summary"
I hope this article will help you with the Android program.