Note that there are some explanatory texts on larger screens.

plurals
  1. PODeleting and updating the database
    primarykey
    data
    text
    <p>Iam a beginner in android SQLite.Following is the code for student database I got from one site.I understood the code but I don't know how to update and delete any row.Can someone please help?What should I add to the following code?</p> <pre><code>public class MainActivity extends Activity { String fname,lname,email; SQLiteDatabase db; TableRow tableRow; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db=openOrCreateDatabase("MyDB1",MODE_PRIVATE, null); db.execSQL("CREATE TABLE IF NOT EXISTS Student(fname VARCHAR,lname VARCHAR,email VARCHAR);"); } public void data(View view) { EditText edittext1=(EditText )findViewById(R.id.firstname); EditText edittext2=(EditText )findViewById(R.id.lastname); EditText edittext3=(EditText )findViewById(R.id.email); fname=edittext1.getText().toString(); lname=edittext2.getText().toString(); email=edittext3.getText().toString(); db.execSQL("INSERT INTO Student VALUES('"+fname+"','"+lname+"','"+email+"');"); } public void showdata(View view) { Cursor c=db.rawQuery("SELECT * from Student", null); int count= c.getCount(); c.moveToFirst(); TableLayout tableLayout = new TableLayout(getApplicationContext()); tableLayout.setVerticalScrollBarEnabled(true); TableRow tableRow; TextView textView,textView1,textView2,textView3,textView4,textView5; tableRow = new TableRow(getApplicationContext()); textView=new TextView(getApplicationContext()); textView.setText("Firstname"); textView.setTextColor(Color.RED); textView.setTypeface(null, Typeface.BOLD); textView.setPadding(20, 20, 20, 20); tableRow.addView(textView); textView4=new TextView(getApplicationContext()); textView4.setText("LastName"); textView4.setTextColor(Color.RED); textView4.setTypeface(null, Typeface.BOLD); textView4.setPadding(20, 20, 20, 20); tableRow.addView(textView4); textView5=new TextView(getApplicationContext()); textView5.setText("Email"); textView5.setTextColor(Color.RED); textView5.setTypeface(null, Typeface.BOLD); textView5.setPadding(20, 20, 20, 20); tableRow.addView(textView5); tableLayout.addView(tableRow); for (Integer j = 0; j &lt; count; j++) { tableRow = new TableRow(getApplicationContext()); textView1 = new TextView(getApplicationContext()); textView1.setText(c.getString(c.getColumnIndex("fname"))); textView2 = new TextView(getApplicationContext()); textView2.setText(c.getString(c.getColumnIndex("lname"))); textView3 = new TextView(getApplicationContext()); textView3.setText(c.getString(c.getColumnIndex("email"))); textView1.setPadding(20, 20, 20, 20); textView2.setPadding(20, 20, 20, 20); textView3.setPadding(20, 20, 20, 20); tableRow.addView(textView1); tableRow.addView(textView2); tableRow.addView(textView3); tableLayout.addView(tableRow); c.moveToNext() ; } setContentView(tableLayout); db.close(); } public void close(View view) { System.exit(0); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload