Alberto Michelis Well-Known Member Licensed User Longtime User Feb 24, 2015 #1 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
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 Longtime User Feb 24, 2015 #2 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. Upvote 0
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 Longtime User Feb 24, 2015 #3 Try this Code: Copy 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. Upvote 0
Try this Code: Copy 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 Longtime User Feb 25, 2015 #4 Real Easy with dbutils Code: Copy 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 Upvote 0
Real Easy with dbutils Code: Copy 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