OK, start with the same framework, but instead of the Dictionary object, use
an XML Document:
dim ar, xmldoc, root, node
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
if isArray(ar) then
set xmldoc=createobject("msxml2.FreeThreadedDomDocumen t")
set root=xmldoc.createElement("root")
set xmldoc.documentElement=root
for i = 0 to ubound(ar,2)
set node=xmldoc.createElement(ar(0,i))
node.text= ar(1,i)
root.appendChild node
Set Session("variables")=xmldoc
next
else
response.write "no data was retrieved"
end if
Here is an example of processing that document:
dim xmldoc, root, node
set xmldoc=Session("variables")
set rootxmldoc.documentElement
for each node in root.childNodes
response.write node.nodeName & ": """
response.write node.text & """<BR>"
next
Michael wrote:
Thank you for respond. I'd like to explain Idea of script I need. All
variable i am using on website I'd like to use as constants during web
session. I mean to load all constants(that kept in varName field) at
the beginning of session and after that to use them in all pages
while web user is connected.
The another ideas I think could be generating the asp file(every time
after editing my table) which will "include" file and will be used by
"include" statement. The XML style Code very appreciated. Thanks
again Michael
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:ef**************@TK2MSFTNGP02.phx.gbl...
>Michael wrote:
>>Hi. I am trying to declare variables based on DB column.
I have a table with 2 columns:
"varname" and "varvalue".
values for example:
varName: 'varPhone'
varValue: '450-111-2222'
During the looping I'd like to declare on asp page variables that
taken from varname column and assign values taken from varValue
column. i think the Execute method can help me, but failed to do
this.
Execute is "evil" :
http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx.
>>>
Some code I am going to use is here:
Do while not rs.eof
first=rs("varName')
second=rs("varValue")
Execute(first & "=" & second) ?????????
rs.movenext
Loop
Thanks a lot for help
Michael
Why are you doing this? It's not like you are going to even know the
names of these variables until runtime. What is the point?
Let's assume you have some valid reason for doing this. Are you
planning to store these things in Session or Application?
If so, I would suggest storing it as an xml document (if you need
some code for this, let us know).
If not, I would recommend using a Dictionary object instead of using
the "evil" Execute method For the best efficiency, I would suggest
using a GetRows array, like this:
dim ar, dict
sql="select varname,varvalue from table where ... "
set rs=conn.execute(sql,,1)
if not rs.eof then ar=rs.Getrows
rs.close:set rs=nothing
conn.close: set conn=nothing
if isArray(ar) then
set dict=createobject("scripting.dictionary")
for i = 0 to ubound(ar,2)
dict.add ar(0,i), ar(1,i)
next
else
response.write "no data was retrieved"
end if
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"