Android Question android.database.sqlite.SQLiteException: no such table: field1 (code 1 SQLITE_ERROR[1]): , while compiling: INSERT INTO field1 VALUES (?)

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hi everyone, I have an application designed to work with sqlite databases, I loaded an existing database from another application and as soon as I create an insertion of data on an edittext and store it in the database I receive an error as if it cannot find the field1 table , I point out that this database works in another application, where am I wrong?
I attach the offending code
btnsalvacucinaon:
Private Sub btnsalvacucinaon_Click
    If txtcucinaon .Text="" Then
        mp1.Load(File.DirAssets,"alert.wav")
        mp1.Play
        MsgboxAsync("Devi prima inserire l'indirizzo ip prima di salvare","AVVISO !!")
        
    Else
        dbsql1.ExecNonQuery2("INSERT INTO field1 VALUES (?)", Array As String(txtcucinaon.Text))
        txtcucinaon.Text= (txtcucinaon.Text)
        dbcursor1.Close
        mp1.Load(File.DirAssets,"cash.wav")
        mp1.Play
        btnsalvacucinaon.Text="Elimina"
        MsgboxAsync("Indirizzo IP aggiunto premuto qualche secondo il pulsante elimina se vuoi eliminarlo","ESEGUITO")
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
I point out that this database works in another application, where am I wrong?
Not posting the databasefile/Structure.

Noone can help you if you hide the information totally

Best is to upload a small project (including databasefile) to see the problem

Edit: Do you really name a TABLE field1? Looks like a bad Databasedesign.
 
Last edited:
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
this a little part of code not work with database working in other app.
 

Attachments

  • test.zip
    103.3 KB · Views: 111
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Your Activity_Create should be:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    mp1.Initialize
    Activity.LoadLayout("Layout")
    If File.Exists(File.DirInternal, "comande.db") = False Then ' se non trova il database  allora lo copia usando il rigo di sotto altrimenti non fa nulla.
        File.Copy(File.DirAssets, "comande.db", File.DirInternal, "comande.db")
        Log ("dbsql copio File")
    End If
    
    If FirstTime Then
        dbsql1.Initialize(File.DirInternal, "comande.db", True) ' inizializza il database
    End If    
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
With the code of Mahares your project works OK.

But, what is the purpose of your database.
I have seen that you have 55 tables called field1 to field55.
And each table has one column called dataxx, where xx is the number of the field.
This database structure surprises me.
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
Did you check your SQL statement as @jahswant pointed out???
The table name is missing or did you call your table field1???
initially I created this database for order management for restaurants, in fact it works very well on the program while on this new program it doesn't, I called the tables field1 up to field 55 while the fields were called data1 up to data55, now in the new app this database is not working
 
Upvote 0
Top