Android Question datatype mismatch: INSERT INTO table VALUES

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello everyone, I state that I am not good in sqlite, I'm making a program with 33 fields edittex and be able to save and recall all in a simple way, but when I go to save tells me this error: sqliteexception: datatype mismatch: INSERT INTO table VALUES
see photo,
someone is willing to help me?
other question .... if some fields are empty at the time of the rescue, the database must be in error '.
I trust in you
part of the code

B4X:
Sub btnnuovo_Click
    If txtlocale.Text="" Then
    Msgbox("Devi prima inserire un locale sulla casella di testo","AVVISO")
    Else
    Dim NewID As Int
    Try
        NewID = SQL1.ExecQuerySingleResult("SELECT max(id) FROM tabella ") + 1
    Catch
        NewID = 1
    End Try   
    SQL1.ExecNonQuery("INSERT INTO tabella VALUES('" & NewID & "','" & txtlocale.text & "','" & txtuser.text & "','"& txtpassword.text  & "','" & txtpiattaforma.Text &"','" & txtincasso.Text &"','"& txtdata.Text & "','" & txtora.Text &  "','"& txtfido.Text & "','" & txtpercentuale.Text & "','" & txtcaricati.Text & "','" & txtresiduo.Text & "','"& txtconsumato.Text & "','" & txtquotanoi.Text & "','" & txtquotalocale.Text & "','" & txtrimanenza.Text & "','" & txtstorico.Text & "','" & txtweb.Text & "','" & txtesattore.Text & "','" & txtnotespesevarie.Text & "','" & txtspesevarie.Text & "','" & txtspesecarburante.Text & "','" & txtaccontoagente.Text & "','" & txtaccontolocale.Text & "','" & txtnotespeselocale.Text & "','" & txtspeselocale.Text & "','" & txtdareagente.Text & "','" & txtdarelocale.Text & "','" & txtnote.Text & "','" & txtpercentualeagente.Text & "','" & txtquotaagente.Text & "','" & txtstoricoquotalocale.Text & "','" & txtstoricoincassi.Text & "')")
       
    Msgbox("Locale aggiunto al database","MEMORIZZATO")
    End If
    'btnleggi_Click
End Sub
 

Attachments

  • ooo.png
    25.5 KB · Views: 632

fifiddu70

Well-Known Member
Licensed User
Longtime User
I attach my project with the panels placed
if you press button: scheda locale you show all field in other panel,
I wish that when I insert different parameters in the EditText they are stored, then the home of the project is a listview, I would like to see the local in the listview and I would like to view by selecting it in the edittex saved data. I would also like the program does not fail when the fields are empty.
with the save button, I want to save all the fields, with the edit button I would like to update the fields with the delete button I would like to delete the selected locale in the listview, while the enter button I would like to send data to an FTP.
 

Attachments

  • sample.zip
    381.2 KB · Views: 231
Upvote 0

LucaMs

Expert
Licensed User
Longtime User

I try to take a look, because ... I did not understand a tube! (this is not an international sentence, I guess)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
However, if you really want to do it that way, you only have a problem to solve:
manage the fields to save in the db in the right order.

I advise you to using at least the Types, if not the classes.
Create a type with all 33 fields, since it uses only one table.
example:
Type typRec (ID as int, Locale as string, ...).

You should also create a list with the names of the fields in the table.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
You have this 3 lines:

B4X:
    MyFields=Array As Object(NewID,txtlocale.text,txtuser.Text,txtpassword.Text,txtpiattaforma.Text,txtincasso.Text,txtdata.Text,txtora.Text,txtfido.Text,txtpercentuale.Text,txtcaricati.Text,txtresiduo.Text,txtconsumato.Text,txtquotalocale.Text,txtrimanenza.Text,txtweb.Text,txtesattore.Text,txtnotespesevarie.Text,txtspesevarie.Text,txtspesecarburante.Text,txtaccontoagente.Text,txtaccontolocale.Text,txtnotespeselocale.Text,txtdareagente.Text,txtdarelocale.Text,txtnote.Text,txtpercentualeagente.Text,txtquotaagente.Text,txtquotalocale.Text, txtstoricoincassi.text)  'rest of edittext boxes
    qry = "INSERT INTO tabella VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"  'Account for all fields
    SQL1.ExecNonQuery2(qry,MyFields)

but you must "load" the MyFields array with the "objects" (you are using edittexts) in the same order of the fields in your table.


so, you can't write:
Object(NewID,txtlocale.text,txtuser.Text....

NewID is the 30th field in your table, not the first;
Locale is the 31, not the second;
and so on.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…