Android Question Trying to add an sql record with DButils

Alberto Michelis

Well-Known Member
Licensed User
Hi, Im working with the SqlDbutils example.
Trying to insert a record with the following code...
Query = "INSERT INTO " & Main.DBTableName & _
" (Mercado,Panel,Especie,Moneda)" & _
" values (" & _
" '" & sMercado & "'," & _
" '" & sPanel & "'," & _
" '" & sEspecie & "'," & _
" '" & sMoneda & "' " & _
" )"
clipb.setText(Query)
Msgbox(Query,"")
Main.SQL1.ExecNonQuery(Query)
I get no error but nothig is added to the table.
I set the query to the clipboard, copy it to SqlLite Expert and run it and the record is added ok.
Whats the problem and how can I trap the possible errors?
Thanks
 

klaus

Expert
Licensed User
Try this code:
Query = "INSERT INTO " & Main.DBTableName & _
" values (" & _
" '" & sMercado & "'," & _
" '" & sPanel & "'," & _
" '" & sEspecie & "'," & _
" '" & sMoneda & "' " & _
" )"
I suppose that you have data for all columns.
Otherwise post a small project showing the problem so we could test it.
 

Walter Adriano da Silva

Member
Licensed User
Try this

B4X:
Query = "INSERT INTO ? (Mercado, Panel, Especie, Moneda) VALUES (?, ?, ?, ?)"

Main.SQL1.ExecNonQuery2(Query, Array As Object(Main.DBTableName, sMercado, sPanel, sEspecie, sMoneda))
I don't know why you want show a Msgbox, but isn't a good idea mix the code for DB and UI.
 

Reviewnow

Active Member
Licensed User
Real Easy with dbutils


B4X:
Dim ListOfMaps As List
ListOfMaps.Initialize

Dim dbmap As Map
dbmap.Initialize

'Add your values to a map
''Useage  dbmap.put("YOUR_COLUMN_NAME",VALUE_TO_INSERT)
 
  dbmap.put("Mercado",sMercado)
  dbmap.put("Panel", sPanel)
  dbmap.put("Especie",sEspecie)
  dbmap.put("Moneda",sMoneda)
 
  'Add the Field Mapping to the list
  ListOfMaps.Add(dbmap)
 
  'Finally insert the record
     'Depends on dbutils
     dbutils.InsertMaps(Main.SQL1, Main.DBTableName,ListOfMaps)
     'Clear The ListOfMaps after insert
     ListOfMaps.Clear
 
Top