Lovemonkey16
Programmer
Hello, I am a relative newbie to JavaScript and I am running into and issue which I can't seem to get a hold of. I am creating a Web Page which will connect to a small Access Database to keep track of logins. The issue comes when I try to run an SQL statement and to be put into a RecordSet. Here is my code:
<SCRIPT language=javascript event=onclick for=cmdLogin>
var ID = Student_ID1.value;
var pass = Password1.value;
var strID = "'" + ID + "' ";
var strPass ="'" + pass + "'";
var conn = new ActiveXObject("ADODB.Connection");
var strConn = new String("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Login_Data.mdb");
var rs = new ActiveXObject("ADODB.Recordset");
var SQL1 = "select Student_ID from Student WHERE Student_ID = ";
var SQL2 = " Password = ";
var SQL = SQL1 + strID + SQL2 + strPass;
conn.Open(strConn,"","");
alert(SQL);
rs.Open (SQL, conn);
alert("Got Through rs.Open");
var RowCount = 0;
while (!(rs.EOF))
{
rs.MoveNext();
RowCount = RowCount +1;
}
alert(RowCount);
</SCRIPT>
I use the Alerts to help me determine where I am getting stuck. When I Open the page and then hit the Login button, I get the Alert which shows me my SQL command that I want to send, which seems to be in the correct format. However after that I get nothing. So obviously it is not getting through the rs.Open I have determined it is something with my String varible because when I put in 'rs.Open("select * from table")' I get through and the script works correctly. I have tried in the past to convert the 'ID' and 'pass' to strings using the toString() method with no success.
I am hoping someone can help me out and explain what I am doing wrong here. Thank you in advance for any and all help you can provided.
FYI:
'ID' is a text box
and 'pass' an INPUT box of 'type = password'
both contained inside a FORM.
<SCRIPT language=javascript event=onclick for=cmdLogin>
var ID = Student_ID1.value;
var pass = Password1.value;
var strID = "'" + ID + "' ";
var strPass ="'" + pass + "'";
var conn = new ActiveXObject("ADODB.Connection");
var strConn = new String("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Login_Data.mdb");
var rs = new ActiveXObject("ADODB.Recordset");
var SQL1 = "select Student_ID from Student WHERE Student_ID = ";
var SQL2 = " Password = ";
var SQL = SQL1 + strID + SQL2 + strPass;
conn.Open(strConn,"","");
alert(SQL);
rs.Open (SQL, conn);
alert("Got Through rs.Open");
var RowCount = 0;
while (!(rs.EOF))
{
rs.MoveNext();
RowCount = RowCount +1;
}
alert(RowCount);
</SCRIPT>
I use the Alerts to help me determine where I am getting stuck. When I Open the page and then hit the Login button, I get the Alert which shows me my SQL command that I want to send, which seems to be in the correct format. However after that I get nothing. So obviously it is not getting through the rs.Open I have determined it is something with my String varible because when I put in 'rs.Open("select * from table")' I get through and the script works correctly. I have tried in the past to convert the 'ID' and 'pass' to strings using the toString() method with no success.
I am hoping someone can help me out and explain what I am doing wrong here. Thank you in advance for any and all help you can provided.
FYI:
'ID' is a text box
and 'pass' an INPUT box of 'type = password'
both contained inside a FORM.