Javascript ADO recordset open method not working. Parametrized queries

258 views Asked by At

I am creating a web page and have some javascript code to insert some information from the webpage to MS access database. I am using ADO connections and record set but I am having a problem with the open method.

This is a snippet of the code I am having trouble with

var name =document.StatusReports.empname.value;
var query = "Select * From reportForm Where EmployeeName =" + name;

    alert(query);

    if(adoRS.Open(query, adoConn, 1, 3));

Name is just a variable that will hold the value of a text box. (this works) if I use alert(query) everything displays nicely: Select * From reportForm Where EmployeeName = kevin As if the concatenation worked fine. But then If I try to open the connection with that query I get this error:

SCRIPT3600: No value given for one or more required parameters. 

As if it didn't recognize the concatenation.

NOTE: IT works wihtout the concatenation. For example if I hardcode a value:

 var query = "Select * From reportForm Where EmployeeName = kevin";

But that is not the purpose of course.

UPDATE: I think the problem is that the query is not parametrized. I remember in Java this happened to me but I parametrized ther query and I would be done. Not sure how to paramterize queries using javascript

1

There are 1 answers

0
Rick Hitchcock On BEST ANSWER

The following query will produce an error in Access, because it's trying to compare two field names: "EmployeeName" and "kevin":

Select * From reportForm Where EmployeeName = kevin

The following query should not produce an error, because it's comparing "EmployeeName" against a string value of "kevin":

Select * From reportForm Where EmployeeName = 'kevin'

Put the search string name in quotes like this:

var query = "Select * From reportForm Where EmployeeName ='" + name + "'";