0

I am trying to write to database based on the id. I am having trouble specifying the id number with an input box. If I set the number in the code it works fine, but I'm getting an error when I try grabbing the id from input.

My HTML has an input field with id='idnumber'

   var path= "C:\\Users\\joshr\\fullpathtomyfile\\filename.accdb";  
   var idnumber = document.getElementById('idnumber').value;

   var cn = new ActiveXObject("ADODB.Connection");
   var rs = new ActiveXObject("ADODB.Recordset");
   var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + path;
   cn.Open(strConn);  
   rs.Open("SELECT MAX(Resolved) FROM reporting", cn);     
   rs.MoveFirst;
   var maxID = rs.Fields.Item(0);
   maxID = maxID + 1;
   rs.Close();  

   var sql = "UPDATE reporting SET Resolved='YES' WHERE ID='+idnumber+'"; 

I have also have tried:

   var sql = "UPDATE reporting SET Resolved='YES' WHERE ID='idnumber'";
   var sql = "UPDATE reporting SET Resolved='YES' WHERE ID=idnumber";

This one works but i need the number to be user input.

    var sql = "UPDATE reporting SET Resolved='YES' WHERE ID=3";
    rs.Open(sql, cn);
    cn.Close();

I also tried

    var sql = "UPDATE reporting SET Resolved='YES' WHERE                                                                                              .       ((reporting.ID)='"+idnumber+"')";

The result of this is "Data type mismatch in criteria expression."

EDIT: I still need help with this

joshrt24
  • 33
  • 7
  • This is basic [string concatenation](https://stackoverflow.com/questions/16124032/js-strings-vs-concat-method). `... WHERE ID=" + parseInt(idnumber, 10);` If your environment supports it, you can also use [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), eg ``var sql = `UPDATE reporting SET Resolved='YES' WHERE ID=${parseInt(idnumber, 10)}`;`` – Phil Oct 12 '17 at 23:58
  • I tried var sql = "UPDATE reporting SET Resolved='YES' WHERE ID=" + parseInt(idnumber, 10); and I didnt get any errors, but it didnt write to the table . the second example you gave me returned Syntax error in query expression 'ID=${parseInt(idnumber, 10)}'. – joshrt24 Oct 13 '17 at 00:20
  • any other suggestions? – joshrt24 Oct 17 '17 at 12:55

0 Answers0