title: Check if record exists in databse with Javascript
body: <p>I am trying to check if a record exists using javascript (I know is not the safest way to do it) but all of this is for internal use and safety is not an issue.</p>
  
  <p>So I opened a recordset,</p>
  
  <pre><code>rs.Open("SELECT * FROM clie Where N_CLIENT =" + textbox1+ " AND C_POST_CLIENT = '" + textbox2+ "'",connection)
  </code></pre>
  
  <p><code>textbox1</code> and <code>textbox2</code> are the values I am looking into the clie table, but first I need to check if the record exists. I tried assigning that <code>rs.Open</code> to a variable and then compare it with something but it did not work</p>
  
  <p>I tried using a <code>RecordCount</code> but I kept getting -1. I read it was not intended for that, and that it should not be used for looking for records so there has to be another way to do this.</p>
  
  <p><em><strong></em> UPDATE <em>_</em></strong></p>
  
  <p>Here is the whole function I am working on</p>
  
  <pre><code>function RecordExists(textfield1, textfield2)
  {
  var connection = new ActiveXObject("ADODB.Connection") ;
      var connectionstring = "UID=admin;PWD=password";
      connection.Open(connectionstring);
      var rs = new ActiveXObject("ADODB.Recordset");
      var textbox1= new String();
      var textbox2=new String();
      textbox1= document.getElementById(textfield1).value;
      textbox2= document.getElementById(textfield2).value;
  
      var isEmpty=new String();
  
      rs.Open("SELECT count(*) as pers FROM clie HAVING N_CLIENT =" + textbox1+ " AND C_POST_CLIE = '" + textbox2+ "'",connection);
  
      alert(rs.recordcount);
      //alert(rs.fields(1));
      //isEmpty = rs.Open("pers");
      alert("Empty"+isEmpty);
      if(pers=0)
          alert("Record does not exist! pers="+pers);
      else if(pers=1)
          alert("Record exists! pers="+pers);
      else
          alert("not working");
      rs.close;
      connection.close;
      }
  }
  </code></pre>