General discussion

Locked

populating web page from Access database

By plantogo2000 ·
Need the procedure in HTML so that a drop-down list box is populated from an Access database.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

populating web page from Access database

by allenhunter In reply to populating web page from ...

I am going to assume that you have no experience with connecting a database to the web. Please forgive me if I state things that you arlready know.

The following code uses VBScript in an Active Server Page to populate a list box with data from anAccess database.

First, open the connection to the database.

Dim connString
Dim DataConn
Set DataConn = Server.CreateObject ("ADODB.Connection")
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/inetpub/wwwroot/non_credit/courses.mdb"
DataConn.Open connString

Where the connString will depend on your system and where the files are stored, etc.

Next, create the recordset.

Dim GroupRS
Set GroupRS = Server.CreateObject ("ADODB.RecordSet")
GroupRS.ActiveConnection = DataConn
GroupRS.Source = "SELECT * FROM tblgroups"
GroupRS.Open

The Source property of the recordset is the SQL to retieve the data from your database.

Next, the code to populate the list box.

Response.write "<select>"
Do while not GroupRS.EOF
Response.write "<option value='" & GroupRS ("groupname"0) & "'>" & GroupRS ("groupname") & "</option>"
GroupRS.MoveNext
Loop
Response.write "</select>"

This loops through the recordset and puts the data in the value attribute and the text of each option tag. Don't forget that when using nested quotes, to alternate between double and single quotes or you might close string to soon. This can cause many errors.

Finaly close therecordset and data connections.

GroupRS.Close
DataConn.Close
Set DataConn = nothing

Put the following line at the top of the page...

<%@ Language=VBScript %>

enclose all of the VBSript code within the script tags - <% and %>
thensave the page with an .asp extension and you should be ready to go!

e-mail me if you have any problems and I'll see what I can do.
Allen
allenhunter@mindspring.com

Collapse -

populating web page from Access database

by allenhunter In reply to populating web page from ...

There are two lines of code listed above that are broken up and need to be on one line for the code to work.

The first is in the first block of code. The line that starts with "Source=E:..." needs to be on the previous line;
"...Data Source=E:..."

The other one is in the third block of code. The line that starts with "("groupname")..." needs to be added to the line above it
"...GroupRS ("groupname")..."

Allen

Collapse -

populating web page from Access database

by Shanghai Sam In reply to populating web page from ...

Poster rated this answer

Collapse -

populating web page from Access database

by plantogo2000 In reply to populating web page from ...

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums