S_Seydel
11 years agoContributor
SQL insert with JScript arrays and adodb
Hello, I have a problem with the following function: function sqlInsert()
{
// static name of the database table
var table = "Names";
// calls the function which opens the database con...
- 11 years ago
Hi,
You need to pass either strings or the safeArray arrays. You code doesn’t work as you pass the JScript array the the AddNew method. You can use two approaches:
- Update your table in the following way:
recordset.AddNew(); recordset("forename") = "John"; recordset("surname") = "Doe"; recordset.Update;- Convert a JScript array to safeArray in the following way:
function ArrayToSafeArray(array) { var dictionary = new ActiveXObject("Scripting.Dictionary"); for (var i = 0; i < array.length; i++) { dictionary.add(i, array[i]); } return dictionary.Items(); } var columns = new Array("forename", "surname"); var values = new Array("John", "Doe"); recordset.AddNew(ArrayToSafeArray(columns), ArrayToSafeArray(values)); recordset.Update();