Android Question SQL Database

sonistp

Member
hello everyone.
I need your help. I am just learning about database.
I got a problem, when first i inserted my record from my table into list view it wass okay., my record in database showed the same as text in my listview. But, when i updated using my program, the database didnot updated as showed by my listview. So do with my listview, didnot updated when i have updated my database using SQL Lite.

Sorry for my English..
 

Attachments

  • dbase_soni.zip
    18.1 KB · Views: 86

DonManfred

Expert
Licensed User
Longtime User
You did changed the Database using your APP?
Oryou did changed the database on your pc and then install a new app with this db including? DID you copy the new DB before you use it or do you reuse the available database?
 
Upvote 0

sonistp

Member
I reused my database. I edited my database by using software SQL, but nothing updated in my list view. And also, whe i did update in my app, nothing happened in my database.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is in this line:
connection.mysql.ExecNonQuery("UPDATE tb_pa SET code_unit='" & edittext1.Text & "', type_unit='" & edittext2.Text & "', plan_pa= '" & edittext3.Text & "' WHERE id='" & unitid & "'")
When you update, unitid is an empty string. Therefore nothing is updated.
Replace the line by this one:
connection.mysql.ExecNonQuery("UPDATE tb_pa SET code_unit='" & edittext1.Text & "', type_unit='" & edittext2.Text & "', plan_pa= '" & edittext3.Text & "' WHERE id='" & Main.id & "'")

Then there are some other mistakes:
1. The DBUtils module is now replaced by a the DBUtils B4X Library. You should remove the module and use the library.
Download the DBUtils.b4xlib file and copy it to the AdditionalLibraries\B4X folder.
If you don't have yet set the AdditionalLibraries folder structure look at Additional libraries folder in the B4X Basic Language Booklet.
B4X Libraries are explained HERE in the same booklet.
Then you might read the B4X Documentation Booklets.
2. Your layouts are not OK. The input_data layout is landscape but the screen is in portrait, therefore parts of the views are outsides the screen in portrait. Take of the text colors.
3. When you click on an item in ListView1 the return value is the first value you entered. You might use the id value as the return value to be unique.
In the click routine you use a For/Next loop, as each entry should be unique there should be only one result therefore no need for the loop.
4. In the database the id field is defined with NUMERIC UNIQUE, this is not a 'standard' data type in SQLite. It would be better to set it as INTEGER PRIMARY KEY.
Then you read it back as a String, id = connection.mycur.GetString("id"),
you should use an Int variable instead. Declare id As Int and read it with id = connection.mycur.GetInt("id").
5. When you go from the input_data Activity back to the Main Activity your program crashes. I changed it in the modified version.
6. For SQLite query results you might use ResultSet instead of Cursor. ResultSet is cross-platform, Cursor is only B4A.

I would suggest you to read the B4X Documentation Booklets, there exist a specific booklet about SQLite and watch Erels' video tutorials to get a better knowledge on B4A.

Attached your project with some modifications.
 

Attachments

  • dbase_soni_1.zip
    18.2 KB · Views: 77
Upvote 0

sonistp

Member
The problem is in this line:
connection.mysql.ExecNonQuery("UPDATE tb_pa SET code_unit='" & edittext1.Text & "', type_unit='" & edittext2.Text & "', plan_pa= '" & edittext3.Text & "' WHERE id='" & unitid & "'")
When you update, unitid is an empty string. Therefore nothing is updated.
Replace the line by this one:
connection.mysql.ExecNonQuery("UPDATE tb_pa SET code_unit='" & edittext1.Text & "', type_unit='" & edittext2.Text & "', plan_pa= '" & edittext3.Text & "' WHERE id='" & Main.id & "'")

Then there are some other mistakes:
1. The DBUtils module is now replaced by a the DBUtils B4X Library. You should remove the module and use the library.
Download the DBUtils.b4xlib file and copy it to the AdditionalLibraries\B4X folder.
If you don't have yet set the AdditionalLibraries folder structure look at Additional libraries folder in the B4X Basic Language Booklet.
B4X Libraries are explained HERE in the same booklet.
Then you might read the B4X Documentation Booklets.
2. Your layouts are not OK. The input_data layout is landscape but the screen is in portrait, therefore parts of the views are outsides the screen in portrait. Take of the text colors.
3. When you click on an item in ListView1 the return value is the first value you entered. You might use the id value as the return value to be unique.
In the click routine you use a For/Next loop, as each entry should be unique there should be only one result therefore no need for the loop.
4. In the database the id field is defined with NUMERIC UNIQUE, this is not a 'standard' data type in SQLite. It would be better to set it as INTEGER PRIMARY KEY.
Then you read it back as a String, id = connection.mycur.GetString("id"),
you should use an Int variable instead. Declare id As Int and read it with id = connection.mycur.GetInt("id").
5. When you go from the input_data Activity back to the Main Activity your program crashes. I changed it in the modified version.
6. For SQLite query results you might use ResultSet instead of Cursor. ResultSet is cross-platform, Cursor is only B4A.

I would suggest you to read the B4X Documentation Booklets, there exist a specific booklet about SQLite and watch Erels' video tutorials to get a better knowledge on B4A.

Attached your project with some modifications.
Thaknkyou very much for your help Mr. Klaus really helpful..
 
Upvote 0
Top