PDA

View Full Version : Access data from database


Haidar
04-23-2010, 11:28 AM
Hey!

Trying to access information from database with this code, i have hardly tried to fix it but it wont work. Someone who can helps? :confused:

<%
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb")%>
objConn.Open

DIM mySQL
mySQL = "SELECT * FROM myCustomers"

DIM objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
%>

<% Response.Write objRS("Username") %>

<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

Old Pedant
04-23-2010, 07:42 PM
What error do you get from what line??

The ASP coding, per se, is correct. But it doesn't make lots of sense. Just for example, you will always be getting *ALL* fields from *ALL* records in that myCustomers table.

And of course all sorts of errors could occur, depending on your actual database.

For example, that code assumes:
(1) the "database.mdb" file exists
(2) the "database.mdb" file exists in the same folder as the ASP page you are showing there
(3) the table "myCustomers" exists in that database
(4) the field "Username" exists in that "myCustomers" table

Haidar
04-27-2010, 10:00 PM
Hum... I think i got the wrong code then. If you remeber when you helped me with the access level. I have in the mysql a table called Admin and there is all the user with perrmission level. I have created for theme another field called "job" so i want each user can se what job they have right now.

I think this code just need to get a bit edit?:confused: