0

I have a "Customer Information" form in my application. I need the data filled in on this form to be saved into a "Transaction Record" file saved on the SD card. This will be a master list of transactions this app has completed. How can I save this data to a growing record?

Below is an example of the form.

Name: Sue
License: D1234567890
Address: 742 Evergreen Terrace
State: XY
Phone: 111-222-3344

I need to save this in some kind of growing database...

| transaction  | name    | license        | address                | state | phone
---------------------------------------------------------------------------------------
| 4322         | joe     | D4657373888    | 2200 sudderthe road    |WZ     | 9543939124
| 4323         | kim     | D0987655432    | 1st elbow street       |KM     | 5551234444
| 4324         | sue     | D1234567890    | 742 evergreen terrace  |XY     | 1112223344

This database will be accessed and edited by a few different areas of the application. So once I get this figured out I can accomplish a lot for the overall app.

Eventually I have to get the app to upload this transaction record to our website...I take on that hurdle when it comes...

I am using this code in the "Next" buttons onClick :

String custname = name.getText().toString();
String custlicense = license.getText().toString();
String custstate = state.getText().toString();
String custaddress = address.getText().toString();
String custcity = city.getText().toString();
String custzip = zip.getText().toString();
String custphone = phone.getText().toString();
String custemail = email.getText().toString();
String custdriver = driver.getText().toString();

So I guess I just need to figure out how to save those variables to some kind of database.

(I kind of use this place to help me figure out what it is i actually need to do...so as im writing this im starting to answer my own question. :P)

jcan
  • 23
  • 3

2 Answers2

0

Use SqlLite, aka class SQLiteDatabase. You put all your CRUD methods in a subclass of SQLiteOpenHelper. There's some setting up to do, but ultimately to write rows to the database, you'll need code like the following:

ContentValues values = new ContentValues();
values.put ("custname", custname);
values.put ("cuslicense", custlicense);
...
getWritableDatabase().insertOrThrow ("CustomerInformation", null, values);
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • If this answer helped, please upvote. If you feel it's the correct answer, then check it. That will encourage people to answer future questions :) – Peri Hartman Oct 17 '13 at 23:58
0

Use/Create SQLiteDatabase from SD card. Read this to see how to achieve that.

Community
  • 1
  • 1
minhaz
  • 4,233
  • 3
  • 33
  • 49