Android Question Trying to add an sql record with DButils

Discussion in 'Android Questions' started by Alberto Michelis, Feb 24, 2015.

  1. Alberto Michelis

    Alberto Michelis Active 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
     
  2. klaus

    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.
     
  3. Walter Adriano da Silva

    Walter Adriano da Silva Member Licensed User

    Try this

    Code:
    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.
     
  4. Reviewnow

    Reviewnow Active Member Licensed User

    Real Easy with dbutils


    Code:
    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
     
    wyatt420 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice