Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Obtaining data on ASP

I am trying to obtain data using directly to my page html via ASP <%%> as the code shown below. However, the codes had an error says, "expected end of statement"

<!DOCTYPE html>
<html>
<body>
<h1>My First Display</h1>

<%
Dim cn
Dim rs
Dim filePath

filePath = "C:\MyDb\DbUsers.accdb"

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open ("Provider=Microsoft.ACE.OLEDB.12.0.1; Data Source=" & filePath & "; Persist Security Info=False; Jet OLEDB:Database Password=iErwin")
        rs.Open "Select UserCode, UserName, TelNumber from MyUsers", conn
       
        with rs
          If not .BOF = True And not .EOF = True Then
            var x = .Fields("UserName");
            alert("x");
            response.write "Your order has been sent!"
          else
            alert("No record!");
          End If
         end with
rs.close
cn.close
%>
</body>
</html>
erro1.bmp
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

I've got the same error Ryan, while trying your suggestion. However, I have found other solution that work exactly what I want. I can't figure out which part of your solutions running wrong. I'm still want to know and pursue your solution in spite of having this formula.

<!DOCTYPE html>
<html>
<body>
<h1>My First Display</h1>
<%
Dim connStr, objConn
Dim filePath
filePath = "C:\MyDb\DbUsers.accdb"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open ("Provider=Microsoft.ACE.OLEDB.12.0.1; Data Source=" & filePath & "; Persist Security Info=False; Jet OLEDB:Database Password=iErwin")
Set rs = objConn.execute("Select UserCode, UserName, TelNumber, iPassword from MyUsers where iPassword='i100' ")    
        with rs
          If not .BOF = True And not .EOF = True Then
            response.write (.Fields("UserName"))
            response.write (.Fields("TelNumber"))
          else
            response.write "No record!"
          End If
         end with
rs.close
objConn.close
%>
</body>
</html>
I can't figure out which part of your solutions running wrong. I'm still want to know and pursue your solution in spite of having this formula.
and too quick for my comment!

var x = .Fields("UserName")

Open in new window


is invalid and should be as:

x = .Fields("UserName")

Open in new window


var is for javascript!
An error says, Micro. VBScript runtime.. Object required. That's the error while removing var..
try:

Dim x
x = .Fields("UserName")

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you both of you sirs!