Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
12-19-2006, 06:02 PM #1
- Join Date
- Dec 2006
- Thanked 0 Times in 0 Posts
Browser: MSIE 6 SP1.
OS: Win NT 4.0
Here's the script chunk I'm having trouble with:
function queryDB(qType, op, strVal, oBy, ascDesc)
var oBySetUp = "QAGrades" + "." + "`" + oBy + "`" //this compiles a text string containing order by sequence I'd like to use, oBy is passed in as an argument (text string) from a select option.
//I then append this to the end of either a string prepared for numeric query or a string prepared for a text query:
var qString="SELECT * FROM QAGrades WHERE " + qTypeUser + " " + op + " " + "'" + strVal + "'" + " ORDER BY " + "'" + oBySetUp + "' " + ascDesc
//This is my string prepared for a text query. QAGrades is the name of the table
var qNumeric = "SELECT * FROM QAGrades WHERE " + qTypeUser + " " + op + " " + strVal + " ORDER BY " + "'" + oBySetUp + "' " + ascDesc
//This is my string prepared for a numeric query.
Theres another chunk of script here that determines if we're querying a number or a text string:
var validChars = "0123456789";
for (i = 0; i < strVal.length && isNumber == true; i++)
Char = strVal.charAt(i);
if (validChars.indexOf(Char) == -1)
setStr = qString
setStr = qNumeric
Once we know what the datatype is we then append it into the rSet.Open command as an argument (in red below):
//Setting up the connection string:
var cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\vcResults.mdb";
var adOpenKeyset = 1;
var adLockOptimistic = 3;
var adCmdText = 1;
var adUseClient = 3;
var tdStr = ""
var thStr = ""
quoStr = "\'"
//initialise database and submit the query:
var cObj = new ActiveXObject("ADODB.Connection"); //set up the activex control for the connection to the database
var rSet = new ActiveXObject("ADODB.Recordset"); //setup a Recordset activex to contain the results returned from the query
rSet.CursorLocation = adUseClient //everything will be client side
cObj.CursorLocation = adUseClient
rSet.Open(setStr,cObj,adOpenKeyset,adLockOptimistic,adCmdText); // <---this is where the query is sent to the database (setStr is inherited from the datatype checking routing above (where it says check dType in bold)
for (i =0; i < rSet.Fields.Count; i+=1)
thStr+= "<td class = tdClass>" + rSet.Fields(i).Name + "</td>"
for (rCount = 0; rCount < rSet.RecordCount; rCount+=1)
for(counter = 0; counter <rSet.Fields.Count; counter+=1)
tdStr += "<td> " + rSet.Fields(counter).Value + "</td>"
if (counter =rSet.Fields.Count)
alert("Error! No Records Found! \n\n" + err.description)
alert("I couldn't close, cos errrrrr, I wasn't open!" + '\n\n' + err.description)
document.getElementById("retDiv").innerHTML = "<table><tr>" + thStr + "</tr><tr>" + tdStr + "</table>"
The rest of the script just builds a table to keep the results in (hence all the for loops). All variables:
qType = Query Type (from select option)
op = Operator (From Select Option)
strVal = String Value (From text box)
oBy = Order By (from select box)
ascDesc = Ascending or Descending order? (From Select Option) <--Doesn't work (Value can either be ASC or DESC)
Hope this isn't too garbled, I've tried to outline the problem the best I can.
Thanks for any help you all can give.