Forum Moderators: open

Message Too Old, No Replies

How to process ASP code from an Access database?

Using classic ASP

         

lukioki

10:00 pm on May 25, 2006 (gmt 0)

10+ Year Member



I'm trying to get my server to process ASP code that is in a Access database? I figure the problem is coming from the ASP load order (I'm using classic ASP not .net). Is there a way to input the database content before processing the ASP code?

Here's the code....

Asp Code:
--------------
Dim rs
set con=Server.CreateObject("ADODB.Connection")
con.Provider="Microsoft.Jet.OLEDB.4.0"
con.Open "C:\Database.mdb"
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM Sentence", con

SomeVar= "hi "
D1= rs("Column1")
response.write D1
--------------

The Access database cell rs("Column1") has the following content:
--------------
<%=SomeVar%> how <br><br> are you?
--------------

The desired output is:
--------------
hi how

are you?
--------------

The actual output is:
--------------
<%=SomeVar%> how

are you?
--------------

carguy84

12:53 am on May 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not easily no. You'll have to figure out some way of running the page thru the ASP interpreter a second time if that's even possible.

Chip-

mattglet

1:28 pm on May 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The more commom (and recommended) way to do what you're doing is to store the value you want to show in the database. Then in your ASP page, you will do this:

<%
dim strVar

'--- connect to DB and fill a recordset

strVar = rs("Column1")

'--- close DB
%>

<html>
<%=strVar%>, how are you?
</html>

So if Column1 in your DB contained "Matt", then you would have:

Matt, how are you?

If you want to have the rest of the greeting ("how <br><br> are you?") to be customized, you could also store that in the database and output as needed.

Easy_Coder

2:36 pm on May 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you actually storing your asp code in the database? I don't know how you'd get that to work.

mrMister

2:31 am on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to do something like this...


Dim rs
set con=Server.CreateObject("ADODB.Connection")
con.Provider="Microsoft.Jet.OLEDB.4.0"
con.Open "C:\Database.mdb"
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "SELECT * FROM Sentence", con

SomeVar= "hi "
D1= rs("Column1")
Eval(cStr(D1))

However you can't use the Asp shortcut tags (<%=your code%>) in the database. you'll have tochange the content in column 1 to the following...

Response.write(SomeVar & "how <br><br> are you?")

lukioki

3:36 pm on Jun 6, 2006 (gmt 0)

10+ Year Member



Thank you for your replies.

The suggestion from MattGlet and MrMister is a working solution. However, I was trying to avoid that code order for this particular application.

I'd like to achieve the following functionality

Given: Database, Database_W, Column1, SomeVar
Where: Column1 = "hi <%=SomeVar%> how <br><br> are you?"

  1. Populate an ASP template with a paragraph from Column1 in Database (works as suggested)
  2. Fill the variable SomeVar in the paragraph with words from Database_W. (the problem)

Another way to do this is to split up the paragraph and load SomeVar and the paragraph at the same time like this:

Response.Write rs(Column1) & " " & rs2(SomeVar) & " " & rs(Column2) & " ."</td></tr>

But in a large paragraph with many variables this creates many divisions and awkward editing.

Is there a way to achieve the desired functionality?

Thank you!

mrMister

6:07 am on Jun 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



deleted