Android Question How to read a specific column and row from SQlite(solved-thanks)

f0raster0

Well-Known Member
Licensed User
Longtime User
From User's Guide, 4) SQLite Database
I am using the example wrote for Klaus also the DB: "persons" but I have changed many thing because
I want to read a specific data then show it in an EditText, How could I do it?

Using the code below, I got this error:
"An error has occurred in sub:
Android.database.sqlite.SQLiteException: no such table:persons(Code1):,while compiling:
SELECT*FROM persons
Conitnue?"

B4X:
Sub Button1_Click
    'Dim i As Int
    Dim Cursor1 As Cursor
 
    Cursor1 = SQL1.ExecQuery("SELECT * FROM persons")
    'Cursor1 = SQL1.ExecQuery("SELECT * FROM personas WHERE FirstName = ?")
    Cursor1.Position = 3 'example location3    'set the cursor
    EditText3.Text = Cursor1.GetString("FirstName")    'read the value of the FirstName column
    'EditText4.Text = Cursor1.GetString("LastName")        'read the value of the LasstName column
    'edtCity.Text = Cursor1.GetString("City")                        'read the value of the City column
    Cursor1.Close

End Sub
 

Attachments

  • HelloWorld3.zip
    342.6 KB · Views: 168
Last edited:

Mahares

Expert
Licensed User
Longtime User
You are forgetting to copy the database from Assets folder to the ruta folder: Your activity_create code should be like the code below code. Also, change the text colors of the editetxt3 to say red as it is white on white so you can see the text:
B4X:
Sub Activity_Create(FirstTime As Boolean)
  
    'check if copy in SD or internal memory       
        If File.ExternalWritable Then 
            ruta = File.DirDefaultExternal 'SD
        Else 
            ruta = File.DirInternal 'internal
        End If
    'check if the database already exists
        If File.Exists(ruta, "persons.db") = False Then
            File.Copy(File.DirAssets,"persons.db", ruta, "persons.db")  'Added my Mahares 
        End If
    Activity.LoadLayout("Layout1")
    Activity.Title = "SQLiteTest1"
   
End Sub
 
Upvote 0
Top