Sqlite database problem

systems1

Member
Licensed User
Longtime User
Hi all,

Iam new to android

I created a sample sqlite database program. which insert name of a user to table.

my problem is when i restart emulator and run my sample program i cant see the previous datas i inserted in my table.

Also where is the database located? is it possible to view database

I attached my code herewith.
Please Help me

Regards,
:sign0085::sign0085:
 

klaus

Expert
Licensed User
Longtime User
You should remove these lines in Activity_Create in the display module.
B4X:
Sub Activity_Create(FirstTime As Boolean)
'    If SQL1.IsInitialized = False Then
'        SQL1.Initialize(File.DirDefaultExternal, "test1.db", True)
'    End If
And change this line:
B4X:
cursor1 = Main.SQL1.ExecQuery("SELECT * FROM user")
The database is already declared as a process global object in the Main module so no need to redeclare it in the display module.
In your code in the display module your initialize a NEW database with the same name, so won't find the inserted names.

Best regards.
 
Upvote 0

systems1

Member
Licensed User
Longtime User
Thank you for your replay klaus.

it is fine

But now i got another probelm

i changed this sample program to a student view and add program.

i have two buttons ADD STUDENT , VIEW STUDENT

I added a student and come back to view student. i got the student details in grid.

then i again added a student then i came back to view student ican't find the student there.

I don't understand what is happening here.

I attached my code herewith.

Please Help me.

Regards,
:sign0085::sign0085:
 

Attachments

  • sample2.zip
    8.8 KB · Views: 149
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here you are.
The problem you had is that you filled the ScrollView in Activity_Create and not in Activity_Resume.
When leaving the display activity it's paused and when you come back from the addstudent Activity the Activity_Create routine is not called.
The attached modified program works.
I added also Activity.Finish in the Activity_Pause routines.
Replaced ExitApplication by Activity.Finish in the Main module.

Best regards.
 

Attachments

  • sample3.zip
    13.4 KB · Views: 169
Upvote 0

systems1

Member
Licensed User
Longtime User
yes that's works fine for me

Thank you claus for helping me

Regards,
:sign0142:
:sign0060:
 
Upvote 0
Top