1

I am developing an android application where i need to enter multiple rows in database at a one go, i have 18 rows and 4 columns in my user interface which are edit texts , is it possible to enter all data i data base with one button click , how can i do that ? Here is my code to generate one row

public void addRow(String rowStringOne, String rowStringTwo)
{
// this is a key value pair holder used by android's SQLite functions
ContentValues values = new ContentValues();
values.put(TABLE_ROW_ONE, rowStringOne);
values.put(TABLE_ROW_TWO, rowStringTwo);

// ask the database object to insert the new data
try{db.insert(TABLE_NAME, null, values);}
catch(Exception e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
}
Avi Dhiman
  • 4,905
  • 7
  • 36
  • 69
Nitin
  • 1,948
  • 3
  • 22
  • 53
  • yes but can you post some code please – T9b Jun 28 '11 at 08:10
  • what db system are you using? –  Jun 28 '11 at 08:11
  • there are quite a few steps involved in this process - we need to know what framerwork your web application is developed in, what language you are using, and what database you are using. if you want help on these forums always aim to be verbose. – jcvandan Jun 28 '11 at 08:15
  • I am using Database helper class – Nitin Jun 28 '11 at 08:58
  • you can use transactions – Nipuna Jun 28 '11 at 11:38
  • 1
    Please see this post as to how it is not supported, unless you do some ugly union: http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database –  Jun 28 '11 at 15:20

1 Answers1

1

It depends from where you get the data. You have two possible scenarios.

  1. You have to insert records from other sql table - You can use single sql query that will fetch and insert the records. For more details read this post
  2. You have to insert records already loaded in memory - You can to implement some king of bulk insert. For more details how to use transactions and do bulk insert read this post
Mojo Risin
  • 8,072
  • 5
  • 43
  • 57